Simple decimal select fails

95 views
Skip to first unread message

Micha Koller

unread,
Jan 6, 2012, 12:47:05 PM1/6/12
to PyMySQL Users

Hello,

I'm using PyMySQL3-0.4 with Python 3.2 under Ubuntu Linux and Eclipse.
If a query should give back a decimal result the error message "Cannot
convert %r to Decimal" % value" appears.
What can I do?

Micha


Minimal pyhton example to reproduce:

import pymysql
conn = pymysql.connect(host= "localhost", user="root", passwd="root",
db="xyz")

dbCursor = conn.cursor ()
query ="SELECT 1.0"
dbCursor.execute (query)


Full error message:

Traceback (most recent call last):
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
cursors.py", line 103, in execute
result = self._query(query)
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
cursors.py", line 221, in _query
conn.query(q)
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
connections.py", line 599, in query
self._affected_rows = self._read_query_result()
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
connections.py", line 685, in _read_query_result
result.read()
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
connections.py", line 873, in read
self._read_result_packet()
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
connections.py", line 886, in _read_result_packet
self._read_rowdata_packet()
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
connections.py", line 911, in _read_rowdata_packet
converted = converter(self.connection, field, data)
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
converters.py", line 337, in convert_decimal
return Decimal(data)
File "/usr/lib/python3.2/decimal.py", line 660, in __new__
raise TypeError("Cannot convert %r to Decimal" % value)
TypeError: Cannot convert b'1.0' to Decimal

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/mk/arbeit/mytest.py", line 12, in <module>
dbCursor.execute (query)
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
cursors.py", line 108, in execute
self.errorhandler(self, exc, value)
File "/home/mk/.local/lib/python3.2/site-packages/pymysql/
connections.py", line 182, in defaulterrorhandler
raise Error(errorclass, errorvalue)
pymysql.err.Error: (<class 'TypeError'>, TypeError("Cannot convert
b'1.0' to Decimal",))

Jay Summet

unread,
Jan 6, 2012, 12:59:33 PM1/6/12
to pymysq...@googlegroups.com
You'll need to upgrade to the latest version in the github repository to
fix this error.

You can follow my directions here:

http://www.summet.com/dmsi/html/pymysql.html#installing-pymysql-for-python3

(Note, even release version 0.5 has this bug, so you'll need to draw
from the git repository until they release a new version...)

Jay

Reply all
Reply to author
Forward
0 new messages