Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with bottle-pymysql
#1
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",)
Reply
#2
Someone please?
Reply
#3
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",)
Reply
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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.
Reply
#6
try
@app.route('/log/<page>')
def log(page, pymydb):
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
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
Reply
#8
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
for the second one try
def index(pymydb, page='index.html'):
it looks like pymydb should be last positional argument
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating tables with pymysql using Xampp newbie1 0 2,077 Jul-15-2020, 11:10 AM
Last Post: newbie1
  pymysql.err.InterfaceError nikos 1 3,000 Feb-24-2019, 02:07 PM
Last Post: nikos
  How to access routes using Bottle Framework nikos 5 4,205 Feb-13-2019, 11:43 PM
Last Post: nikos
  unable to import pymysql IMuriel 3 7,294 Jan-08-2019, 08:56 PM
Last Post: IMuriel
  Passing a query value from a Bottle html template to a route with an encoding nikos 0 2,895 Sep-30-2018, 03:29 AM
Last Post: nikos
  Insert data to SQL through pymysql and flask iainstott 3 7,661 Oct-24-2017, 03:04 PM
Last Post: iainstott
  please explain Bottle runtime log Kebap 4 7,420 Sep-22-2016, 05:40 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020