Can't Encode Pic

Victor Subervi victorsubervi at gmail.com
Thu Nov 26 13:32:12 EST 2009


On Thu, Nov 26, 2009 at 1:10 PM, Victor Subervi <victorsubervi at gmail.com>wrote:

> On Thu, Nov 26, 2009 at 11:52 AM, MRAB <python at mrabarnett.plus.com> wrote:
>
>> Victor Subervi wrote:
>>
>>> On Thu, Nov 26, 2009 at 10:03 AM, Carsten Haese <carsten.haese at gmail.com<mailto:
>>> carsten.haese at gmail.com>> wrote:
>>>
>>>    cursor.execute('update products set pic1=%s where ID=1',
>>>    (MySQLdb.Binary(pic1),))
>>>
>>>    [That comma between the two closing parentheses is not a typo. Do not
>>>    leave it out!]
>>>
>>>
>>> A problem occurred in a Python script. Here is the sequence of function
>>> calls leading up to the error, in the order they occurred.
>>>  /var/www/html/angrynates.com/cart/addEdit.py <
>>> http://angrynates.com/cart/addEdit.py>
>>>
>>>   85   print '<body>\n</html>'
>>>   86   db.commit()
>>>   87   cursor.close()
>>>   88
>>>   89 addEdit()
>>> addEdit = <function addEdit>
>>>  /var/www/html/angrynates.com/cart/addEdit.py <
>>> http://angrynates.com/cart/addEdit.py> in addEdit()
>>>
>>>   66       id = 0
>>>   67       cursor.execute(sql)
>>>   68       cursor.execute('update products set pic1=%s where ID=1'
>>> (MySQLdb.Binary(pics[0]),))
>>>   69       for col in colNamesPics:
>>> cursor = <MySQLdb.cursors.Cursor object>, cursor.execute = <bound method
>>> Cursor.execute of <MySQLdb.cursors.Cursor object>>, global MySQLdb = <module
>>> 'MySQLdb' from '/usr/lib64/python2.4/site-packages/MySQLdb/__init__.pyc'>,
>>> MySQLdb.Binary = <function Binary>, pics =
>>> ['\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x01\x00H\x00H\x00\x00\xff\xe1\x13\xd5Exif\x00\x00MM\x00*\x00\x00\x00\x08\x00\x07\x01\x12\x00\x03\x00\x00\x00\x01...\xdb\x9f\x94\xa9\xfds\xc9y\xb1W\xda\xd66\x9azS\x84\xd1\x1f\x93\xa9\xfdG\x0fm\xe3\x84\x01\xc5\x94\xfc\x88\xcf\x06f\xc5_\x7fPS6x\x076*\xff\x00\xff\xd9',
>>> '', '']
>>>
>>> TypeError: 'str' object is not callable
>>>      args = ("'str' object is not callable",)
>>>
>>> Please advise.
>>>
>>
>> On line 68 you have a string literal immediately followed by a tuple, so
>> it looks like you're trying to call a string, hence the exception. Put a
>> comma between the string literal and the tuple.
>>
>
> Hang on. Not done yet. The line of code I gave you was just a test case.
The real ones, and the error they threw, follows:

A problem occurred in a Python script. Here is the sequence of function
calls leading up to the error, in the order they occurred.
 /var/www/html/angrynates.com/cart/addEdit.py
   87   print '<body>\n</html>'
   88   db.commit()
   89   cursor.close()
   90
   91 addEdit()
addEdit = <function addEdit>
 /var/www/html/angrynates.com/cart/addEdit.py in addEdit()
   71       for pic in pics:
   72         sql = 'update %s set %s=%s where ID=%s;' % (t,
colNamesPics[i], '%s', str(id))
   73         cursor.execute(sql, (MySQLdb.Binary(pics[id]),))
   74         i += 1
   75     elif whatDo == 'insert':
cursor = <MySQLdb.cursors.Cursor object>, cursor.execute = <bound method
Cursor.execute of <MySQLdb.cursors.Cursor object>>, sql = 'update products
set pic1=%s where ID=1;', global MySQLdb = <module 'MySQLdb' from
'/usr/lib64/python2.4/site-packages/MySQLdb/__init__.pyc'>, MySQLdb.Binary =
<function Binary>, pics =
['\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x01\x00H\x00H\x00\x00\xff\xe1\x13\xd5Exif\x00\x00MM\x00*\x00\x00\x00\x08\x00\x07\x01\x12\x00\x03\x00\x00\x00\x01...\xdb\x9f\x94\xa9\xfds\xc9y\xb1W\xda\xd66\x9azS\x84\xd1\x1f\x93\xa9\xfdG\x0fm\xe3\x84\x01\xc5\x94\xfc\x88\xcf\x06f\xc5_\x7fPS6x\x076*\xff\x00\xff\xd9'],
id = '1'

TypeError: list indices must be integers
      args = ('list indices must be integers',)

Please advise,
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091126/df1363a6/attachment-0001.html>


More information about the Python-list mailing list