Posts: 76
Threads: 21
Joined: Jan 2017
Feb-14-2019, 01:55 PM
(This post was last modified: Feb-14-2019, 01:55 PM by nikos.)
plugin = bottle_pymysql.Plugin( dbuser='nikos', dbpass='******', dbname='counters', charset = 'utf8', keyword='pymydb' )
app.install(plugin)
# calculate total hits for each and every webpage
pymydb.execute( '''SELECT url from pages ORDER by hits ASC''' ) When i try to run the script i get the error:
Output: NameError("name 'pymydb' is not defined",)
Posts: 76
Threads: 21
Joined: Jan 2017
Posts: 76
Threads: 21
Joined: Jan 2017
Feb-19-2019, 04:27 PM
(This post was last modified: Feb-19-2019, 04:27 PM by nikos.)
plugin = bottle_pymysql.Plugin( dbuser='nikos', dbpass='******', dbname='counters', charset = 'utf8', keyword='pymydb' )
app.install(plugin)
# calculate total hits for each and every webpage
pymydb.execute( '''SELECT url from pages ORDER by hits ASC''' )
def database( pymydb, page ):
....
.... When i try to run the script i get the error:
Output:
Output: NameError("name 'pymydb' is not defined",)
Posts: 8,088
Threads: 154
Joined: Sep 2016
Feb-19-2019, 04:31 PM
(This post was last modified: Feb-19-2019, 04:31 PM by buran.)
Not 100% sure, I think but this will have effect only in route, e.g. something like
@app.route('/hits')
def hits(pymydb):
pymydb.execute( '''SELECT url from pages ORDER by hits ASC''' )
# rest of it to render the page
Posts: 76
Threads: 21
Joined: Jan 2017
Yes, you are right, i have removed it from the function and put it only in the route
@app.route( '/log/<page>' )
def log( pymydb, page ): But still iam getting the same error.
Posts: 8,088
Threads: 154
Joined: Sep 2016
try
@app.route('/log/<page>')
def log(page, pymydb):
Posts: 76
Threads: 21
Joined: Jan 2017
Feb-19-2019, 04:52 PM
(This post was last modified: Feb-19-2019, 04:59 PM by nikos.)
Output: AttributeError: 'NoneType' object has no attribute 'encoding'
and if
@app.route( '/' )
@app.route( '/<page>' )
def index( page='index.html', pymydb ): Output: [Tue Feb 19 18:56:49.296522 2019] [wsgi:error] [pid 31673] [remote 176.92.27.182:1210] SyntaxError: non-default argument follows default argument
Posts: 8,088
Threads: 154
Joined: Sep 2016
(Feb-19-2019, 04:52 PM)nikos Wrote: Output:
AttributeError: 'NoneType' object has no attribute 'encoding'
So, obviously this works. The AttributeError is due to something else in your code
Posts: 8,088
Threads: 154
Joined: Sep 2016
for the second one try
def index(pymydb, page='index.html'): it looks like pymydb should be last positional argument
Posts: 76
Threads: 21
Joined: Jan 2017
First positional arg you mean.
I dont have anything else wrong AttributeError: 'NoneType' object has no attribute 'encoding' is refering to pymydb, perhaps it has no value?
|