MySQLdbd error. Perhpas it isn't installed?

  • Thread starter Íßêïò Ãêñ33ê
  • Start date
Í

Íßêïò Ãêñ33ê

Hello today i deiced to go form python 2.6 to python 3.2.3

although in 2.6 my script runs in the ht enewest python i ge this error:


Traceback (most recent call last):
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute
r = self._query(query)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query
rowcount = self._do_query(q)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query
db.query(q)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "metrites.py", line 193, in <module>
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute
self.errorhandler(self, exc, value)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass(errorvalue)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")



you can also see it at http://superhost.gr

Any ideas what might be the problem?

My webhost (hostgator.com) says that The MySQLdb module is already installed for python 3 on this server.

Can you please tell me what's the nature of this error?

Thank you.
 
M

MRAB

Hello today i deiced to go form python 2.6 to python 3.2.3

although in 2.6 my script runs in the ht enewest python i ge this error:


Traceback (most recent call last):
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute
r = self._query(query)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query
rowcount = self._do_query(q)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query
db.query(q)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "metrites.py", line 193, in <module>
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute
self.errorhandler(self, exc, value)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass(errorvalue)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")



you can also see it at http://superhost.gr

Any ideas what might be the problem?

My webhost (hostgator.com) says that The MySQLdb module is already installed for python 3 on this server.

Can you please tell me what's the nature of this error?

Thank you.
The error's in the SQL.
 
R

rurpy

On 03/26/2013 03:24 PM, Îίκος ΓκÏ33κ wrote:> Hello today i deiced to go form python 2.6 to python 3.2.3
although in 2.6 my script runs in the ht enewest python i ge this error:


Traceback (most recent call last):
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute
r = self._query(query)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query
rowcount = self._do_query(q)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query
db.query(q)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQLsyntax; check the manual that corresponds to your MySQL server version forthe right syntax to use near '%s' at line 1")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "metrites.py", line 193, in <module>
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute
self.errorhandler(self, exc, value)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass(errorvalue)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQLsyntax; check the manual that corresponds to your MySQL server version forthe right syntax to use near '%s' at line 1")



you can also see it at http://superhost.gr

Any ideas what might be the problem?

My webhost (hostgator.com) says that The MySQLdb module is already installed for python 3 on this server.

Can you please tell me what's the nature of this error?

Thank you.

This seems to be the problem line of code:
File "metrites.py", line 193, in <module>
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )

If 'page' is not a string as you expect, but is None or (for example)
a list or something else, you might well end up with invalid SQL when
MySQLdb tries to build the executable sql statement. Sorry I can't
be more specific -- I haven't used MySQLdb and I'm suggesting what I'd
try for any generic DBI module.

If MySQLdb has a way to turn on debugging so that it prints SQL
statements before execution, you might want do that. Then it may be
obvious what is wrong, or if the SQL still looks ok, try copying it
and pasting it in a interactive database session to see what error
occurs.

If not, maybe you can try adding a print statement to your code that
will print the value of 'page'. This will be easier to do if you
can run you code interactively. If you have to run it via a webserver
than maybe you'll need wrap the print output in html commands to make
it visible on the page, or to write it to a file.
 
Í

Íßêïò Ãêñ33ê

Ôç ÔåôÜñôç, 27 Ìáñôßïõ 2013 6:26:06 ð.ì.. UTC+2, ï ÷ñÞóôçò (e-mail address removed) Ýãñáøå:
If not, maybe you can try adding a print statement to your code that
will print the value of 'page'. This will be easier to do if you
can run you code interactively. If you have to run it via a webserver
than maybe you'll need wrap the print output in html commands to make
it visible on the page, or to write it to a file.


I tried what you suggested by doign the following:

print( page )
sys.exit(0)
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )


and the result is printed in the webpage as 'index.html'

so page seem s to be a string but the error is still persistant.
Anything else i need to try?
 
Í

Íßêïò Ãêñ33ê

And also i must show you that 'page' values are calculated by:

# detect how 'index.html' is called and validate variables 'htmlpage' & 'page'
if page and os.path.isfile( '/home/nikos/www/cgi-bin/' + page ):
page = page
elif form.getvalue('show') and os.path.isfile( htmlpage ):
page = htmlpage.replace( '/home/nikos/public_html/', '' )
else:
page = 'index.html'


so in all cases theya re string.

i just dont see whats worng....
 
M

MRAB

Ôç ÔåôÜñôç, 27 Ìáñôßïõ 2013 6:26:06 ð.ì. UTC+2, ï ÷ñÞóôçò (e-mail address removed) Ýãñáøå:



I tried what you suggested by doign the following:

print( page )
sys.exit(0)
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )


and the result is printed in the webpage as 'index.html'

so page seem s to be a string but the error is still persistant.
Anything else i need to try?
A brief look at the documentation tells me that MySQL uses '?' as the
placeholder instead of '%s':

cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, ))
 
N

nagia.retsina

Τη ΤετάÏτη, 27 ΜαÏτίου 2013 6:48:44 μ.μ. UTC+2, ο χÏήστης MRAB έγÏαψε:
A brief look at the documentation tells me that MySQL uses '?' as the

placeholder instead of '%s':



cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, ))

But as i have it used to work withour problem with pyhton 2.6
Why would it be a problem now?
 
N

nagia.retsina

Τη ΤετάÏτη, 27 ΜαÏτίου 2013 6:48:44 μ.μ. UTC+2, ο χÏήστης MRAB έγÏαψε:
A brief look at the documentation tells me that MySQL uses '?' as the

placeholder instead of '%s':



cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, ))

But as i have it used to work withour problem with pyhton 2.6
Why would it be a problem now?
 
Í

Íßêïò Ãêñ33ê

=> 187 print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2])

excepinfo is probably mis-spelled---I have no idea what you intend.l


Python3 raised exceptions in an except: clause giving the double exception message that I don't think you'd have seen in python2. Maybe the purpose isto help novice python programmers who haven't learned to make try: except:clause trap a specific statement looking for specific Errors.

Maybe this line which iuses to work in python 2.6 doesnt in python 3.2.3 ?

do i have to switch it to soemthing else?
 
Í

Íßêïò Ãêñ33ê

=> 187 print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2])

excepinfo is probably mis-spelled---I have no idea what you intend.l


Python3 raised exceptions in an except: clause giving the double exception message that I don't think you'd have seen in python2. Maybe the purpose isto help novice python programmers who haven't learned to make try: except:clause trap a specific statement looking for specific Errors.

Maybe this line which iuses to work in python 2.6 doesnt in python 3.2.3 ?

do i have to switch it to soemthing else?
 
Í

Íßêïò Ãêñ33ê

I had encoding isseus as well!

Now i tried your suggestion changing comma with '%' and now the error is more clear.

Code:
_mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'")


loook at http://superhost.gr please to see the whoel traceback
 
Í

Íßêïò Ãêñ33ê

I had encoding isseus as well!

Now i tried your suggestion changing comma with '%' and now the error is more clear.

Code:
_mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'")


loook at http://superhost.gr please to see the whoel traceback
 
J

Joel Goldstick

I had encoding isseus as well!

Now i tried your suggestion changing comma with '%' and now the error is
more clear.

Code:
_mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in
'where clause'")


loook at http://superhost.gr please to see the whoel traceback


You should print the sql statement to see what is being created. Create
the sql, and assign it to a variable name. Print that. Then execute the
command.
 
Í

Íßêïò Ãêñ33ê

Ôç ÔåôÜñôç, 27 Ìáñôßïõ 2013 9:06:27 ì.ì.. UTC+2, ï ÷ñÞóôçò Joel Goldstick Ýãñáøå:
You should print the sql statement to see what is being created.  Create the > > >sql, and assign it to a variable name.  Print that.  Then execute the command.

Ok Joe, i just tried the followinf as you suggested to me:

try:
sql = '''SELECT hits FROM counters WHERE url = %s'''
print( sql )
cur.execute( sql , (page,) )
data = cur.fetchone()
except MySQLdb.ProgrammingError as e:
print ( "Query Error: ", dir( sys.exc_info()[1] ) )


=========

please look at http://supethost.gr now, weird errors! encoding issues perhaps?!
 
Í

Íßêïò Ãêñ33ê

Ôç ÔåôÜñôç, 27 Ìáñôßïõ 2013 9:06:27 ì.ì.. UTC+2, ï ÷ñÞóôçò Joel Goldstick Ýãñáøå:
You should print the sql statement to see what is being created.  Create the > > >sql, and assign it to a variable name.  Print that.  Then execute the command.

Ok Joe, i just tried the followinf as you suggested to me:

try:
sql = '''SELECT hits FROM counters WHERE url = %s'''
print( sql )
cur.execute( sql , (page,) )
data = cur.fetchone()
except MySQLdb.ProgrammingError as e:
print ( "Query Error: ", dir( sys.exc_info()[1] ) )


=========

please look at http://supethost.gr now, weird errors! encoding issues perhaps?!
 
Í

Íßêïò Ãêñ33ê

Even better:

try:
sql = '''SELECT hits FROM counters WHERE url = %s''' % page
print( sql )
cur.execute( sql )
data = cur.fetchone()
except MySQLdb.ProgrammingError as e:
print ( "Query Error: ", dir( sys.exc_info()[1] ) )

========

sql statement seems okey...
 
Í

Íßêïò Ãêñ33ê

Even better:

try:
sql = '''SELECT hits FROM counters WHERE url = %s''' % page
print( sql )
cur.execute( sql )
data = cur.fetchone()
except MySQLdb.ProgrammingError as e:
print ( "Query Error: ", dir( sys.exc_info()[1] ) )

========

sql statement seems okey...
 
C

Chris Angelico

I had encoding isseus as well!

Now i tried your suggestion changing comma with '%' and now the error is more clear.

Code:
_mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'")

No, don't do that, that opens you up to SQL injection attacks. Read
the responses you've been given:

A brief look at the documentation tells me that MySQL uses '?' as the
placeholder instead of '%s':

cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, ))

This is what you need to do.

ChrisA
 
Í

Íßêïò Ãêñ33ê

Ôç ÔåôÜñôç, 27 Ìáñôßïõ 2013 9:28:35 ì.ì.. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, ))
This is what you need to do.


The following works in python 2.6

Code:
cur.execute( '''SELECT hits FROM counters WHERE url = %s''') , (page,)

is there a difefrence between the above and the follwong which works in python 3.x

Code:
cur.execute( '''SELECT hits FROM counters WHERE url = %s''' , (page,) )

I'am confused. Which one is the correct?

Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,821
Messages
2,569,748
Members
45,726
Latest member
RaleighAll

Latest Threads

Top