Pizzaface/Alexa-Chromecast-Skill-2.0

dbConnect() - NameError: global name 'db' is not defined`

Closed this issue · 21 comments

I've got everything setup, however when I run: python raspberry.py my server returns

Found ChromeCast: ['Vegeta', 'Krypton', 'Terran']
Traceback (most recent call last):
    File "raspberry.py", line 147, in <module>
        dbConnect()
    File "raspberry.py", line 111, in dbConnect
            cur = db.cursor()
NameError: global name 'db' is not defined`

This is screenshot of my current raspberry.py, any idea what I'm doing wrong?

(Also has anyone else noticed that Alexa is more responsive (noticing the Chromecast when #/usr/bin/env python is in the code?)

Additional info:


If I commit the name of my database "chromey" to lines 109-112:

    "def dbConnect(chromey):
        #Set's up the connection to run commands
        cur = db.cursor(chromey.db)

it returns:

    Found ChromeCast: ['Krypton', 'Vegeta', 'Terran']
            Traceback (most recent call last):
                File "raspberry.py", line 148, in <module>
                dbConnect()
         TypeError: dbConnect() takes exactly 1 argument (0 given)

In addition, if i commit the database name "chromey" into lines 148:

       #Loops Continuously to get new commands.
            while True:
                dbConnect(chromey)
                time.sleep(2)

It returns this error:

       Found ChromeCast: ['Krypton', 'Vegeta', 'Terran']
       Traceback (most recent call last):
                    File "raspberry.py", line 148, in <module>
                      dbConnect(chromey)
       NameError: name 'chromey' is not defined

Python3:


If I specify python3 raspberry.py it returns this:

       File "raspberry.py", line 143
            cur.execute("DELETE FROM commands WHERE id=" + str(idOfQuert))
                                                                                                               ^
       TabError: inconsistent use of tabs and spaces in indentation

Any ideas? Perhaps it's the dbConnect?

Sorry about that!

Used an old snippet of code to write this line, and while I had fixed the issue on my Pi, I forgot to update the files on my host. I've since fixed the issue in 8546f6e.

dbConnect accepts no arguments, as it uses the "conn" global set on line 12 of raspberry.py:
conn = pymysql.connect("RASP_PI_DNS", user="MYSQL_USER", passwd="MYSQL_PASS", db="DB_NAME")

As for your Indentation error, I would look and see if it's tabbed out or spaced out. This sometimes happens between programs.

Hey @Pizzaface thanks for getting back to me! This seems to have resolved the global host + NameError issue, many kudos! However now I am getting this:

   Found ChromeCast: ['Krypton', 'Vegeta', 'Terran']
   Traceback (most recent call last):

 File "raspberry.py", line 94, in <module>
       dbConnect()

 File "raspberry.py", line 48, in dbConnect
       cur.execute("SELECT * FROM commands ORDER BY TIMESTAMP DESC LIMIT 1 ;")

 File "/home/transmission/srvr/Alexa/pymysql/cursors.py", line 161, in execute
       result = self._query(query)

 File "/home/transmission/srvr/Alexa/pymysql/cursors.py", line 317, in _query
       conn.query(q)

 File "/home/transmission/srvr/Alexa/pymysql/connections.py", line 835, in query
       self._affected_rows = self._read_query_result(unbuffered=unbuffered)

File "/home/transmission/srvr/Alexa/pymysql/connections.py", line 1019, in _read_query_result
       result.read()

 File "/home/transmission/srvr/Alexa/pymysql/connections.py", line 1302, in read
       first_packet = self.connection._read_packet()

 File "/home/transmission/srvr/Alexa/pymysql/connections.py", line 981, in _read_packet
       packet.check_error()

 File "/home/transmission/srvr/Alexa/pymysql/connections.py", line 393, in check_error
       err.raise_mysql_exception(self._data)

 File "/home/transmission/srvr/Alexa/pymysql/err.py", line 120, in raise_mysql_exception
       _check_mysql_exception(errinfo)

 File "/home/transmission/srvr/Alexa/pymysql/err.py", line 112, in _check_mysql_exception
       raise errorclass(errno, errorvalue)
          pymysql.err.ProgrammingError: (1146, u"Table 'chromey.commands' doesn't exist")

Perhaps I should reclone and start over?

(1146, u"Table 'chromey.commands' doesn't exist") means that your table doesn't exist inside your database. Try just doing "commands" instead. you've already specified the database in your connection string, if that doesn't work, try recloning.

You are correct! I don't have any tables defined...for some reason I'm not able to removed "chromey.commands." I will try recloning this afternoon and let you know how that works.

Just curious, what types of tables have you created within your db?

Thanks again for all of the support @Pizzaface! I really appreciate it!

Not a problem!

You can get my Database Structure from "build.sql" located in the repo.

You rock!

I updated the data tables, no it seems to hang after finding the chromecasts.

Will try to reclone and start over, I'll let you know of my progress. Thanks again @Pizzaface!

Make sure you define a Chromecast, (I had my ChromeCast name in there still, but have since fixed the issue).

I'd noticed that earlier and swapped it out with my ChromeCast name, additioanlly I just updated my code with the line: chromecast_name = "YOUR_CHROMECAST_NAME"

I'm still hanging after the string of chromecasts are returned.

Then it's because you haven't issued any commands, try issuing a command.

On Sat, Jul 23, 2016 at 12:57 PM Noirad notifications@github.com wrote:

I'd noticed that earlier and swapped it out with my ChromeCast name,
additioanlly I just updated my code with the line: chromecast_name =
"YOUR_CHROMECAST_NAME"

I'm still hanging after the string of chromecasts are returned.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJjV6qzO9MG1SNj1C0648wgU11YSzAvjks5qYkfkgaJpZM4JSd_D
.

Alexa "There was a problem with the requested skills response. In app I see this error.

I'm guessing these errors are due to my configuration of the app in AWS?

Are you getting any issues in Lambda?

On Sat, Jul 23, 2016 at 1:12 PM Noirad notifications@github.com wrote:

Alexa "There was a problem with the requested skills response. In app I
see this error
https://drive.google.com/open?id=0B76FmSgsTcs2ODg4MmFFTE1qVE0.

I'm guessing these errors are due to my configuration of the app in AWS?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJjV6ixhQksgCkMd5SNlKS11mOqJRkiMks5qYkuQgaJpZM4JSd_D
.

It looks like I've isolated the problem to the setup of the Lambda Function. Once I complete the setup, it results in this error:

{
  "errorMessage": "Unable to import module 'index'"
}

Here's the CloudWatch log:

> Event Data
> START RequestId: d7053329-5129-11e6-bdd7-154f0ce2b955 Version: $LATEST 
> Unable to import module 'index': No module named index  
> END RequestId: d7053329-5129-11e6-bdd7-154f0ce2b955 
> REPORT RequestId: d7053329-5129-11e6-bdd7-154f0ce2b955    Duration: 0.34 ms   Billed 
> Duration: 100 ms Memory Size: 128 MB  Max Memory Used: 14 MB

I'm fairly sure everything else is working right. I can connect to the database remotely. I can try to edit rows of the database and see the raspberry.py application respond to my (invalid) entires. So I'm thinking that index.py file is where my breakdown is occurring.

Also, If you've got any tips on manually controlling raspberry.py by way of wither CLI commands or manual database entries to control the chromecast that would be great. I just want to see that I've got everything sorted on that end too (if possible). I think I might be running into noobish issues with mysql when making attempts at manual entries.

Thank you for all of the support @Pizzaface, I really appreciate your help!

Try creating a test event in lambda with your test query, and take a
picture of the response.

On Sat, Jul 23, 2016 at 6:35 PM Noirad notifications@github.com wrote:

Currently this:
https://drive.google.com/open?id=0B76FmSgsTcs2dnpFaEcySmVGTEU The
target Lambda application returned a failure response. Lambda issue is
appearing.

Is there a command line to test the apps ability to control Chromecast
manually?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJjV6rkotMsFuMtKoimzEKrRY2Y0jZCeks5qYpdGgaJpZM4JSd_D
.

Hey @Pizzaface not sure if the email feature in github forwards updates to comments but is that what you meant? re my earlier comment:

"It looks like I've isolated the problem to the setup of the Lambda Function. Once I complete the setup, it results in this error:

{
  "errorMessage": "Unable to import module 'index'"
}
Here's the CloudWatch log:
> Event Data
> START RequestId: d7053329-5129-11e6-bdd7-154f0ce2b955 Version: $LATEST 
> Unable to import module 'index': No module named index  
> END RequestId: d7053329-5129-11e6-bdd7-154f0ce2b955 
> REPORT RequestId: d7053329-5129-11e6-bdd7-154f0ce2b955    Duration: 0.34 ms   Billed 
> Duration: 100 ms Memory Size: 128 MB  Max Memory Used: 14 MB
I'm fairly sure everything else is working right. I can connect to the database remotely. I can try to edit rows of the database and see the raspberry.py application respond to my (invalid) entires. So I'm thinking that index.py file is where my breakdown is occurring.

Also, If you've got any tips on manually controlling raspberry.py by way of wither CLI commands or manual database entries to control the chromecast that would be great. I just want to see that I've got everything sorted on that end too (if possible). I think I might be running into noobish issues with mysql when making attempts at manual entries.

Can you take a picture of your configuration tab on lambda?

It looks like there's a problem with your zip file. Can you show me the contents?

These are the files stored in alexaChromcecast.zip

It's something wrong with your Zip File, however, I'm unsure what, if you
PM me on Reddit (Pizzaface97), I'd be more than happy to assist you further.

On Sun, Jul 24, 2016 at 12:18 AM Noirad notifications@github.com wrote:

These are the files stored in alexaChromcecast.zip
https://drive.google.com/open?id=0B76FmSgsTcs2cFE5R09zY1BMVkE


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJjV6glSS5zvfaNdc8U46hHudBnJsT97ks5qYueQgaJpZM4JSd_D
.

Awesome @Pizzaface, thank you so much!