MySQLdbd error. Perhpas it isn't installed?

Discussion in 'Python' started by Íßêïò Ãêñ33ê, Mar 26, 2013.

  1. 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.
    Íßêïò Ãêñ33ê, Mar 26, 2013
    #1
    1. Advertising

  2. Íßêïò Ãêñ33ê

    MRAB Guest

    On 26/03/2013 21:24, Îίκος ΓκÏ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 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.
    MRAB, Mar 27, 2013
    #2
    1. Advertising

  3. Íßêïò Ãêñ33ê

    Guest

    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.
    , Mar 27, 2013
    #3
  4. Ôç ÔåôÜñôç, 27 Ìáñôßïõ 2013 6:26:06 ð.ì.. UTC+2, ï ÷ñÞóôçò Ýãñáøå:

    > 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ê, Mar 27, 2013
    #4
  5. 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....
    Íßêïò Ãêñ33ê, Mar 27, 2013
    #5
  6. any help here please?
    Íßêïò Ãêñ33ê, Mar 27, 2013
    #6
  7. Íßêïò Ãêñ33ê

    MRAB Guest

    On 27/03/2013 06:42, Íßêïò Ãêñ33ê wrote:
    > Ôç ÔåôÜñôç, 27 Ìáñôßïõ 2013 6:26:06 ð.ì. UTC+2, ï ÷ñÞóôçò Ýãñáøå:
    >
    >> 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?
    >

    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, ))
    MRAB, Mar 27, 2013
    #7
  8. Íßêïò Ãêñ33ê

    Guest

    Τη ΤετάÏτη, 27 ΜαÏτίου 2013 6:48:44 μ.μ. UTC+2, ο χÏήστης MRAB έγÏαψε:
    > On 27/03/2013 06:42, Îίκος ΓκÏ33κ wrote:
    >
    > > Τη ΤετάÏτη, 27 ΜαÏτίου 2013 6:26:06 Ï€.μ. UTC+2, οχÏήστης έγÏαψε:

    >
    > >

    >
    > >> 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?

    >
    > >

    >
    > 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?
    , Mar 27, 2013
    #8
  9. Íßêïò Ãêñ33ê

    Guest

    Τη ΤετάÏτη, 27 ΜαÏτίου 2013 6:48:44 μ.μ. UTC+2, ο χÏήστης MRAB έγÏαψε:
    > On 27/03/2013 06:42, Îίκος ΓκÏ33κ wrote:
    >
    > > Τη ΤετάÏτη, 27 ΜαÏτίου 2013 6:26:06 Ï€.μ. UTC+2, οχÏήστης έγÏαψε:

    >
    > >

    >
    > >> 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?

    >
    > >

    >
    > 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?
    , Mar 27, 2013
    #9
  10. => 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ê, Mar 27, 2013
    #10
  11. => 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ê, Mar 27, 2013
    #11
  12. 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ê, Mar 27, 2013
    #12
  13. 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ê, Mar 27, 2013
    #13
  14. On Wed, Mar 27, 2013 at 2:48 PM, Îίκος ΓκÏ33κ <> wrote:

    > 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
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >



    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.
    --
    Joel Goldstick
    http://joelgoldstick.com
    Joel Goldstick, Mar 27, 2013
    #14
  15. Ôç ÔåôÜñôç, 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ê, Mar 27, 2013
    #15
  16. Ôç ÔåôÜñôç, 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ê, Mar 27, 2013
    #16
  17. 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ê, Mar 27, 2013
    #17
  18. 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ê, Mar 27, 2013
    #18
  19. On Thu, Mar 28, 2013 at 5:48 AM, Íßêïò Ãêñ33ê <> wrote:
    > 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:

    On Thu, Mar 28, 2013 at 3:48 AM, MRAB <> wrote:
    > 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
    Chris Angelico, Mar 27, 2013
    #19
  20. Ôç ÔåôÜñôç, 27 Ìáñôßïõ 2013 9:28:35 ì.ì.. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    > On Thu, Mar 28, 2013 at 3:48 AM, MRAB <> wrote:
    > > 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.



    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.
    Íßêïò Ãêñ33ê, Mar 27, 2013
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad
    Replies:
    3
    Views:
    411
    Kevin Spencer
    Jan 12, 2004
  2. Learner
    Replies:
    4
    Views:
    2,073
    Learner
    Jan 27, 2006
  3. blackwater dev
    Replies:
    4
    Views:
    224
    Ezra Zygmuntowicz
    Aug 2, 2005
  4. Grehom
    Replies:
    1
    Views:
    168
    Grehom
    Jun 15, 2007
  5. L. D. James

    Perl's installed module isn't recognized

    L. D. James, Mar 14, 2008, in forum: Perl Misc
    Replies:
    3
    Views:
    144
    L. D. James
    Mar 14, 2008
Loading...

Share This Page