Python Forum

Full Version: Issue with bottle-pymysql
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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",)
Someone please?
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",)
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
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.
try
@app.route('/log/<page>')
def log(page, pymydb):
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
(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
for the second one try
def index(pymydb, page='index.html'):
it looks like pymydb should be last positional argument
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?
Pages: 1 2