Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Can't Encode Pic

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


victorsubervi at gmail

Nov 26, 2009, 5:47 AM

Post #1 of 17 (629 views)
Permalink
Can't Encode Pic

Hi;
I have the following code:

import cgitb; cgitb.enable()
import cgi
import MySQLdb
from login import login
user, passwd, db, host = login()
db = MySQLdb.connect(host, user, passwd, db)
cursor= db.cursor()
form = cgi.FieldStorage()
pic1 = form.getfirst('pic1')
cursor.execute('update products set pic1=%s where ID=1;' % pic1)

which throws the following error:

/var/www/html/angrynates.com/cart/addEdit.py
81 print '<body>\n</html>'
82 db.commit()
83 cursor.close()
84
85 add_edit()
add_edit = <function add_edit>
/var/www/html/angrynates.com/cart/addEdit.py in add_edit()
63 id = 0
64 pic1 = form.getfirst('pic1')
65 cursor.execute('update products set pic1=%s where ID=1;' % pic1)
66 # while id < len(pics):
67 # cursor.execute('update products set %s=%s where ID=%s;',
(colNamesPics[id], pics[id], str(id)))
cursor = <MySQLdb.cursors.Cursor object>, cursor.execute = <bound method
Cursor.execute of <MySQLdb.cursors.Cursor object>>, pic1 =
'\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'
/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py in
execute(self=<MySQLdb.cursors.Cursor object>, query='update products set
pic1=\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x01\x00H\x00H\x00\x00\xff\xe1\x13...6\x9azS\x84\xd1\x1f\x93\xa9\xfdG\x0fm\xe3\x84\x01\xc5\x94\xfc\x88\xcf\x06f\xc5_\x7fPS6x\x076*\xff\x00\xff\xd9
where ID=1;', args=None)
144 db = self._get_db()
145 charset = db.character_set_name()
146 query = query.encode(charset)
147 if args is not None:
148 query = query % db.literal(args)
query = 'update products set
pic1=\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x01\x00H\x00H\x00\x00\xff\xe1\x13...6\x9azS\x84\xd1\x1f\x93\xa9\xfdG\x0fm\xe3\x84\x01\xc5\x94\xfc\x88\xcf\x06f\xc5_\x7fPS6x\x076*\xff\x00\xff\xd9
where ID=1;', query.encode = <built-in method encode of str object>, charset
= 'latin1'

UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 25:
ordinal not in range(128)
args = ('ascii', 'update products set
pic1=\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x01\x00H\x00H\x00\x00\xff\xe1\x13...6\x9azS\x84\xd1\x1f\x93\xa9\xfdG\x0fm\xe3\x84\x01\xc5\x94\xfc\x88\xcf\x06f\xc5_\x7fPS6x\x076*\xff\x00\xff\xd9
where ID=1;', 25, 26, 'ordinal not in range(128)')
encoding = 'ascii'
end = 26
object = 'update products set
pic1=\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x01\x00H\x00H\x00\x00\xff\xe1\x13...6\x9azS\x84\xd1\x1f\x93\xa9\xfdG\x0fm\xe3\x84\x01\xc5\x94\xfc\x88\xcf\x06f\xc5_\x7fPS6x\x076*\xff\x00\xff\xd9
where ID=1;'
reason = 'ordinal not in range(128)'
start = 25


So I added UTF-8 encoding and got this error:


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
81 print '<body>\n</html>'
82 db.commit()
83 cursor.close()
84
85 add_edit()
add_edit = <function add_edit>
/var/www/html/angrynates.com/cart/addEdit.py in add_edit()
62 sql = 'update products set %s;' % sqlUpdate
63 id = 0
64 pic1 = unicode(form.getfirst('pic1'), 'utf-8')
65 cursor.execute('update products set pic1=%s where ID=1;' % pic1)
66 # while id < len(pics):
pic1 undefined, builtin unicode = <type 'unicode'>, form =
FieldStorage(None, None, [FieldStorage('whatDo',...e('pic2', '', ''),
FieldStorage('pic3', '', '')]), form.getfirst = <bound method
FieldStorage.getfirst of FieldStor...('pic2', '', ''), FieldStorage('pic3',
'', '')])>

UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0:
unexpected code byte
args = ('utf8',
'\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',
0, 1, 'unexpected code byte')
encoding = 'utf8'
end = 1
object =
'\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'
reason = 'unexpected code byte'
start = 0


So then I added UTF-16 encoding and got this error:


/var/www/html/angrynates.com/cart/addEdit.py
81 print '<body>\n</html>'
82 db.commit()
83 cursor.close()
84
85 add_edit()
add_edit = <function add_edit>
/var/www/html/angrynates.com/cart/addEdit.py in add_edit()
62 sql = 'update products set %s;' % sqlUpdate
63 id = 0
64 pic1 = unicode(form.getfirst('pic1'), 'utf-16')
65 cursor.execute('update products set pic1=%s where ID=1;' % pic1)
66 # while id < len(pics):
pic1 undefined, builtin unicode = <type 'unicode'>, form =
FieldStorage(None, None, [FieldStorage('whatDo',...e('pic2', '', ''),
FieldStorage('pic3', '', '')]), form.getfirst = <bound method
FieldStorage.getfirst of FieldStor...('pic2', '', ''), FieldStorage('pic3',
'', '')])>
/usr/lib64/python2.4/encodings/utf_16.py in decode(input=<read-only buffer
ptr 0x1b66e6c4, size 25101>, errors='strict')
14
15 def decode(input, errors='strict'):
16 return codecs.utf_16_decode(input, errors, True)
17
18 class StreamWriter(codecs.StreamWriter):
global codecs = <module 'codecs' from '/usr/lib64/python2.4/codecs.pyc'>,
codecs.utf_16_decode = <built-in function utf_16_decode>, input = <read-only
buffer ptr 0x1b66e6c4, size 25101>, errors = 'strict', builtin True = True

UnicodeDecodeError: 'utf16' codec can't decode bytes in position 0-1:
illegal UTF-16 surrogate
args = ('utf16',
'\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',
0, 2, 'illegal UTF-16 surrogate')
encoding = 'utf16'
end = 2
object =
'\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'
reason = 'illegal UTF-16 surrogate'
start = 0


Finally, I tried UTF-32 encoding and got this error:


/var/www/html/angrynates.com/cart/addEdit.py
81 print '<body>\n</html>'
82 db.commit()
83 cursor.close()
84
85 add_edit()
add_edit = <function add_edit>
/var/www/html/angrynates.com/cart/addEdit.py in add_edit()
62 sql = 'update products set %s;' % sqlUpdate
63 id = 0
64 pic1 = unicode(form.getfirst('pic1'), 'utf-32')
65 cursor.execute('update products set pic1=%s where ID=1;' % pic1)
66 # while id < len(pics):
pic1 undefined, builtin unicode = <type 'unicode'>, form =
FieldStorage(None, None, [FieldStorage('whatDo',...e('pic2', '', ''),
FieldStorage('pic3', '', '')]), form.getfirst = <bound method
FieldStorage.getfirst of FieldStor...('pic2', '', ''), FieldStorage('pic3',
'', '')])>

LookupError: unknown encoding: utf-32
args = ('unknown encoding: utf-32',)


Please advise.
TIA,
Victor


carsten.haese at gmail

Nov 26, 2009, 7:03 AM

Post #2 of 17 (607 views)
Permalink
Re: Can't Encode Pic [In reply to]

Victor Subervi wrote:
> Hi;
> I have the following code:
>
> import cgitb; cgitb.enable()
> import cgi
> import MySQLdb
> from login import login
> user, passwd, db, host = login()
> db = MySQLdb.connect(host, user, passwd, db)
> cursor= db.cursor()
> form = cgi.FieldStorage()
> pic1 = form.getfirst('pic1')
> cursor.execute('update products set pic1=%s where ID=1;' % pic1)
>
> which throws the following error:
>
> [snip UnicodeDecodeErrors and various blind guesses...]
>
> Please advise.

The UnicodeDecodeErrors are a red herring. The real problem is that
you're using string interpolation (the %-operator) to pass the image
data to the database, so your code is force-feeding binary junk directly
into the query string. This results in an SQL query that's not
syntactically correct.

In order to pass values to the database safely, you need to use
parameter binding. In this case, that'll look something like this:

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!]

Note that I'm not using string interpolation to shoehorn the picture
contents into the query string. I'm passing two arguments to
cursor.execute(). The first is the query template, with a %s placeholder
for your image contents. (Note that the query template is a plain ASCII
string, so all your Unicode-related problems will disappear in a puff of
magic.) The second argument is a tuple containing the actual parameters
to be filled into the query by the database engine. This query needs
only one parameter, so I'm making a 1-tuple containing the picture
contents, wrapped inside a MySQLdb.Binary object to tell the database
that this is a binary object.

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net

--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 26, 2009, 8:19 AM

Post #3 of 17 (605 views)
Permalink
Re: Can't Encode Pic [In reply to]

On Thu, Nov 26, 2009 at 10:03 AM, Carsten Haese <carsten.haese [at] gmail>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
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 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.
TIA,
V


python at mrabarnett

Nov 26, 2009, 8:52 AM

Post #4 of 17 (605 views)
Permalink
Re: Can't Encode Pic [In reply to]

Victor Subervi wrote:
> On Thu, Nov 26, 2009 at 10:03 AM, Carsten Haese <carsten.haese [at] gmail
> <mailto:carsten.haese [at] gmail>> 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.
--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 26, 2009, 10:10 AM

Post #5 of 17 (601 views)
Permalink
Re: Can't Encode Pic [In reply to]

On Thu, Nov 26, 2009 at 11:52 AM, MRAB <python [at] mrabarnett> wrote:

> Victor Subervi wrote:
>
>> On Thu, Nov 26, 2009 at 10:03 AM, Carsten Haese <carsten.haese [at] gmail<mailto:
>> carsten.haese [at] gmail>> 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.
>

Thank you. The devil is in the details...and well employed in s/w
development :/
V


victorsubervi at gmail

Nov 26, 2009, 10:32 AM

Post #6 of 17 (601 views)
Permalink
Re: Can't Encode Pic [In reply to]

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

> On Thu, Nov 26, 2009 at 11:52 AM, MRAB <python [at] mrabarnett> wrote:
>
>> Victor Subervi wrote:
>>
>>> On Thu, Nov 26, 2009 at 10:03 AM, Carsten Haese <carsten.haese [at] gmail<mailto:
>>> carsten.haese [at] gmail>> 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


carsten.haese at gmail

Nov 26, 2009, 10:52 AM

Post #7 of 17 (601 views)
Permalink
Re: Can't Encode Pic [In reply to]

Victor Subervi wrote:
> 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:
> [...]
> 73 cursor.execute(sql, (MySQLdb.Binary(pics[id]),))
> [...]
>
> TypeError: list indices must be integers
> args = ('list indices must be integers',)
>
> Please advise,

I know the answer, but I'm not going to spoon-feed it to you this time,
since even a mediocre programmer should be able to figure this one out,
and you really need to start thinking for yourself if you ever want to
grow as a programmer.

How much time did you spend trying to figure out what that error message
is telling you? What thought processes, if any, have you followed?

--
Carsten Haese
http://informixdb.sourceforge.net

--
http://mail.python.org/mailman/listinfo/python-list


python at mrabarnett

Nov 26, 2009, 11:12 AM

Post #8 of 17 (598 views)
Permalink
Re: Can't Encode Pic [In reply to]

Victor Subervi wrote:
> On Thu, Nov 26, 2009 at 1:10 PM, Victor Subervi <victorsubervi [at] gmail
> <mailto:victorsubervi [at] gmail>> wrote:
>
> On Thu, Nov 26, 2009 at 11:52 AM, MRAB <python [at] mrabarnett
> <mailto:python [at] mrabarnett>> wrote:
>
> Victor Subervi wrote:
>
> On Thu, Nov 26, 2009 at 10:03 AM, Carsten Haese
> <carsten.haese [at] gmail <mailto:carsten.haese [at] gmail>
> <mailto:carsten.haese [at] gmail
> <mailto:carsten.haese [at] gmail>>> 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>
> <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>
> <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
> <http://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
> <http://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',)
>
The traceback explains what the problem is: you're indexing a list, but
the index you're providing isn't an integer.

Remember that an integer is not a string and a string is not an integer.
--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 26, 2009, 1:46 PM

Post #9 of 17 (596 views)
Permalink
Re: Can't Encode Pic [In reply to]

On Thu, Nov 26, 2009 at 2:12 PM, MRAB <python [at] mrabarnett> wrote:

> Victor Subervi wrote:
>
>> On Thu, Nov 26, 2009 at 1:10 PM, Victor Subervi <victorsubervi [at] gmail<mailto:
>> victorsubervi [at] gmail>> wrote:
>>
>> On Thu, Nov 26, 2009 at 11:52 AM, MRAB <python [at] mrabarnett
>> <mailto:python [at] mrabarnett>> wrote:
>>
>> Victor Subervi wrote:
>>
>> On Thu, Nov 26, 2009 at 10:03 AM, Carsten Haese
>> <carsten.haese [at] gmail <mailto:carsten.haese [at] gmail>
>> <mailto:carsten.haese [at] gmail
>> <mailto:carsten.haese [at] gmail>>> 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>
>> <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>
>> <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 <
>> http://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 <
>> http://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',)
>>
>> The traceback explains what the problem is: you're indexing a list, but
> the index you're providing isn't an integer.
>
> Remember that an integer is not a string and a string is not an integer.


I've been caught on that one more than once. Thanks, that did it :)
Happy Thanksgiving.
V


victorsubervi at gmail

Nov 27, 2009, 2:59 AM

Post #10 of 17 (584 views)
Permalink
Re: Can't Encode Pic [In reply to]

On Thu, Nov 26, 2009 at 5:08 PM, Dennis Lee Bieber <wlfraed [at] ix>wrote:

> On Thu, 26 Nov 2009 13:32:12 -0500, Victor Subervi
> <victorsubervi [at] gmail> declaimed the following in
> gmane.comp.python.general:
>
>
> > 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]),))
>
> Please study the Python language documents... AND the DB-API PEP...
>

I have read them from cover to cover many times. I just wish everything
stuck :(

>
> sql = "update %s set %s=%%s where ID = %%s" % (t, colNamesPics[i])
> #sets the table/field names, escapes the %s on the DB-API
> placeholders [.MySQLdb, internally, uses string interpolation, which is
> why the placeholder is the same %s, which confuses many]
>
> cursor.execute(sql, (MysQLdb.Binary(pics[id]), id))
> # you don't have to use str(id) since that is the MEANING of %s as a
> placeholder -- generate a normal string representation of whatever the
> supplied parameter is (and the nature of MySQLdb is such that it WILL be
> a string with any internal quotes escaped, and wrapped in SQL quotes
> before getting to the replacement point).
>
> The following complained that there weren't enough arguments:

for pic in pics:
sql = 'update %s set %s=%%s where ID=%s;' % (t, colNamesPics[i],
'%s', str(id))
cursor.execute(sql, (MySQLdb.Binary(pics[int(i)]),), )

Thus, it appears that using a % to escape a % is not what is called for
here! Did I miss something again? So I changed it to:

for pic in pics:
sql = 'update %s set %s=%s where ID=%s;' % (t, colNamesPics[i],
'%s', str(id))
cursor.execute(sql, (MySQLdb.Binary(pics[int(i)]),), )

(diff: %s=%s)

That states that everything worked fine, and it does work fine when I insert
one image. However, when I go to update (the same code is used for the pics
for both insert and update), and try to insert a second image, it doesn't
insert even though it throws no error! If I try to print out all the
variables, including the actual image that is being updated, everything
prints out just fine! Why would the above statements work for inserting one
image but not a second??


> Oh, and finally -- since you generate the SQL statement from scratch
> on each pass of the loop, why even bother with a variable named sql?
>
> cursor.execute("""update %s
> set %s=%%s
> where ID=%%s"""
> % (t,
> colNamesPics[i]),
> (MySQLdb.Binary(pics[id]), id) )
>
> Puts everything in one place, formats it in a somewhat more legible way
> (to me, at least, where the "where" clause is on a line by itself, the
> various "set" parameters are on lines, etc.; the Python string
> interpolation parameters are on one line, and the MySQLdb parameters are
> on another line)
>

I tried combining the two statements and that didn't work either. Same
problems as above.

>
>
> I'm not going to look for the other problem -- this thread has shown
> a tendency of:
>
> It doesn't work, what's wrong?
>
> <answer to first problem>
>
> I tried that, now it does this, why?
>
> <answer to second problem>
>
> etc.
>
> There has been no evidence of one ever referencing documentation in the
> attempt to resolve the matter on one's own.


It is becoming clear to me that utilizing the docs is an art. At least I
(perhaps because I am less adept at the art of programming than many) must
study the docs cover to cover many times, over many years (as my skills
improve), to get to the point where I know what to look for where and when I
need it, to know how to formulate the right questions and thus seek the
right answers on my own. It has taken me many years just to get to the point
of realizing that. And you have helped me to realize that now in your post
(as you have helped me many times with other issues).

Nothing hinting at having
> opened an interactive Python console and typing statements into it as an
> experiment to see what may work, or what changes may break something.
>

Please explain how this makes a difference. If I have the error in hand from
trying to run the code through the Web--either printed to screen or gathered
from the errors log--what need of opening the python interpreter, where I
would have to type everything in by hand (since I'm right now working on
others' computers and don't have right-click ability)?
TIA,
V


rami.chowdhury at gmail

Nov 27, 2009, 6:02 AM

Post #11 of 17 (583 views)
Permalink
Re: Can't Encode Pic [In reply to]

On Fri, Nov 27, 2009 at 02:59, Victor Subervi <victorsubervi [at] gmail> wrote:
> On Thu, Nov 26, 2009 at 5:08 PM, Dennis Lee Bieber <wlfraed [at] ix>
> wrote:
>> Nothing hinting at having
>> opened an interactive Python console and typing statements into it as an
>> experiment to see what may work, or what changes may break something.
>
> Please explain how this makes a difference. If I have the error in hand from
> trying to run the code through the Web--either printed to screen or gathered
> from the errors log--what need of opening the python interpreter

If you are content to run your code through the Web, and iterate
through versions of it there, then that's up to you. I'd suggest using
the interactive interpreter when you can, though -- most Python
programmers that I have encountered find it extremely helpful. In
particular, it can be invaluable in examining short snippets of code
-- such as the segments that are giving you trouble -- without
rerunning the whole program.

When I am debugging errors such as this, what I typically do is snip
out the particular bit that is causing the problem and run it in the
interactive interpreter, experimenting with changes to it until it
works as I want it to. Perhaps such a method would help you in
debugging as well? Certainly it would enable you to give the list a
little more information about what you have and haven't tried when
coming here with a problem...
--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 27, 2009, 7:08 AM

Post #12 of 17 (582 views)
Permalink
Re: Can't Encode Pic [In reply to]

On Fri, Nov 27, 2009 at 9:02 AM, Rami Chowdhury <rami.chowdhury [at] gmail>wrote:

> On Fri, Nov 27, 2009 at 02:59, Victor Subervi <victorsubervi [at] gmail>
> wrote:
> > On Thu, Nov 26, 2009 at 5:08 PM, Dennis Lee Bieber <
> wlfraed [at] ix>
> > wrote:
> >> Nothing hinting at having
> >> opened an interactive Python console and typing statements into it as an
> >> experiment to see what may work, or what changes may break something.
> >
> > Please explain how this makes a difference. If I have the error in hand
> from
> > trying to run the code through the Web--either printed to screen or
> gathered
> > from the errors log--what need of opening the python interpreter
>
> If you are content to run your code through the Web, and iterate
> through versions of it there, then that's up to you. I'd suggest using
> the interactive interpreter when you can, though -- most Python
> programmers that I have encountered find it extremely helpful. In
> particular, it can be invaluable in examining short snippets of code
> -- such as the segments that are giving you trouble -- without
> rerunning the whole program.
>

I usually do. I'm in a peculiar situation now, broke and rebuilding,
borrowing other people's computers, etc. Won't last too much longer :)

>
> When I am debugging errors such as this, what I typically do is snip
> out the particular bit that is causing the problem and run it in the
> interactive interpreter, experimenting with changes to it until it
> works as I want it to. Perhaps such a method would help you in
> debugging as well? Certainly it would enable you to give the list a
> little more information about what you have and haven't tried when
> coming here with a problem...
>

How should I do that in this instance? Here's the problem: the form on the
previous page supplies an uploaded image to the second page which is then
inserted into a MySQL table. The difficulty I am having is that for some
reason it's not inserting. The form inserts the first image but not the
second. When I print out the sql query I am submitting, less the image
itself, it prints correctly. When I print out the image itself, it also
prints correctly. So I don't understand where the problem could possibly be.
I appreciate your help as always :)
V


carsten.haese at gmail

Nov 27, 2009, 8:13 AM

Post #13 of 17 (575 views)
Permalink
Re: Can't Encode Pic [In reply to]

Victor Subervi wrote:
> The difficulty I am having is that for
> some reason it's not inserting. The form inserts the first image but not
> the second.

My guess is that you're not calling db.commit() after inserting the
second image. (If you had shown your code, I wouldn't have to guess.)

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net

--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 27, 2009, 8:58 AM

Post #14 of 17 (578 views)
Permalink
Re: Can't Encode Pic [In reply to]

On Fri, Nov 27, 2009 at 12:13 PM, Carsten Haese <carsten.haese [at] gmail>wrote:

> Victor Subervi wrote:
> > The difficulty I am having is that for
> > some reason it's not inserting. The form inserts the first image but not
> > the second.
>
> My guess is that you're not calling db.commit() after inserting the
> second image. (If you had shown your code, I wouldn't have to guess.)
>

That was the logical guess and yes, it hit the target. I should have known
better. Thank you.
Now, I have this line of code on another page that calls the images once the
database is populated:

print '<img src="getpic.py?pic=%d&id=%d" width="100"></td>\n'
% (a, w)

This is looped through for every value of pic/id returned from the database,
producing the following code on the Web page:

<img src="getpic.py?pic=1&id=1" width="100"></td>
<img src="getpic.py?pic=1&id=2" width="100"></td>

The problem here is that only one of the images prints on the said page!
However, if I surf to those URLs, the images appear! Is it possible that
because I'm passing values to the variables and perhaps simultaneously
calling the script, that it can only fulfill the first request? Is there a
way around that?
TIA,
V


victorsubervi at gmail

Nov 27, 2009, 10:26 AM

Post #15 of 17 (574 views)
Permalink
Re: Can't Encode Pic [In reply to]

On Fri, Nov 27, 2009 at 1:43 PM, Dennis Lee Bieber <wlfraed [at] ix>wrote:

> On Fri, 27 Nov 2009 05:59:39 -0500, Victor Subervi
> <victorsubervi [at] gmail> declaimed the following in
> gmane.comp.python.general:
>
>
> > >
> > > The following complained that there weren't enough arguments:
> >
> > for pic in pics:
> > sql = 'update %s set %s=%%s where ID=%s;' % (t, colNamesPics[i],
> > '%s', str(id))
> > cursor.execute(sql, (MySQLdb.Binary(pics[int(i)]),), )
> >
> I'm pretty sure that isn't what I had typed too... Count the %
>
> sql = "update %s set %s=%%s where ID = %%s" % (t, colNamesPics[i])
>

Thank you, Dennis. This problem is resolved. Since our posts most likely
crossed, and since yours has inadvertently appeared below mine with the
latest problem, I'm reposting it here:

Now, I have this line of code on another page that calls the images once the
database is populated:

print '<img src="getpic.py?pic=%d&id=%d" width="100"></td>\n'
% (a, w)

This is looped through for every value of pic/id returned from the database,
producing the following code on the Web page:

<img src="getpic.py?pic=1&id=1" width="100"></td>
<img src="getpic.py?pic=1&id=2" width="100"></td>

The problem here is that only one of the images prints on the said page!
However, if I surf to those URLs, the images appear! Is it possible that
because I'm passing values to the variables and perhaps simultaneously
calling the script, that it can only fulfill the first request? Is there a
way around that?
TIA,
V


carsten.haese at gmail

Nov 27, 2009, 11:21 AM

Post #16 of 17 (575 views)
Permalink
Re: Can't Encode Pic [In reply to]

Victor Subervi wrote:
> On Fri, Nov 27, 2009 at 12:13 PM, Carsten Haese <carsten.haese [at] gmail
> <mailto:carsten.haese [at] gmail>> wrote:
>
> Victor Subervi wrote:
> > The difficulty I am having is that for
> > some reason it's not inserting. The form inserts the first image
> but not
> > the second.
>
> My guess is that you're not calling db.commit() after inserting the
> second image. (If you had shown your code, I wouldn't have to guess.)
>
>
> That was the logical guess and yes, it hit the target. I should have
> known better. Thank you.
> Now, I have this line of code on another page that calls the images once
> the database is populated:
>
> print '<img src="getpic.py?pic=%d&id=%d"
> width="100"></td>\n' % (a, w)
>
> This is looped through for every value of pic/id returned from the
> database, producing the following code on the Web page:
>
> <img src="getpic.py?pic=1&id=1" width="100"></td>
> <img src="getpic.py?pic=1&id=2" width="100"></td>
>
> The problem here is that only one of the images prints on the said page!
> However, if I surf to those URLs, the images appear!

Are you sure that you're surfing to *exactly* those URLs? When I go to
http://www.angrynates.com/cart/getpic.py?pic=2&id=1, I get an image, but
when I go to http://www.angrynates.com/cart/getpic.py?pic=1&id=2, I get
an error message. I am guessing that you have your pic and id parameter
switched around.

> Is it possible that
> because I'm passing values to the variables and perhaps simultaneously
> calling the script, that it can only fulfill the first request?

That's possible if your script is doing something stupid, but I find my
above guess much more likely.

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net

--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 27, 2009, 12:18 PM

Post #17 of 17 (574 views)
Permalink
Re: Can't Encode Pic [In reply to]

>
> > <img src="getpic.py?pic=1&id=1" width="100"></td>
> > <img src="getpic.py?pic=1&id=2" width="100"></td>
> >
> > The problem here is that only one of the images prints on the said page!
> > However, if I surf to those URLs, the images appear!
>
> Are you sure that you're surfing to *exactly* those URLs? When I go to
> http://www.angrynates.com/cart/getpic.py?pic=2&id=1, I get an image, but
> when I go to http://www.angrynates.com/cart/getpic.py?pic=1&id=2, I get
> an error message. I am guessing that you have your pic and id parameter
> switched around.
>

<sigh> Yes. Sorry. Thanks.
V

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.