On Sun, Jun 27, 2010 at 5:13 PM,  <span dir="ltr">&lt;<a href="mailto:petkovas@dir.bg">petkovas@dir.bg</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Sun, 27 Jun 2010 15:56:23 -0700<br>
 Marc Tompkins &lt;<a href="mailto:marc.tompkins@gmail.com" target="_blank">marc.tompkins@gmail.com</a>&gt; wrote:<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
On Sun, Jun 27, 2010 at 3:20 PM, &lt;<a href="mailto:petkovas@dir.bg" target="_blank">petkovas@dir.bg</a>&gt; wrote:<br>
<br></div><div class="im">
I don&#39;t have any insight into your other piece of code, but here I think you<br>
just need another set of parentheses - so that the string interpolation is<br>
done first, and the result of it becomes the argument to cursor.execute().<br>
I can&#39;t really test it at the moment, but try changing it to:<br>
cursor.execute( (&quot;UPDATE testtable SET jpeg = %s WHERE testtable_n = %s&quot;,<br>
data1, data2) )<br>
<br>
Either that, or break it into two lines:<br>
<br>
myQuery = &quot;UPDATE testtable SET jpeg = %s WHERE testtable_n = %s&quot;, data1,<br>
data2<br>
cursor.execute(myQuery)<br>
<br>
-- <br>
<a href="http://www.fsrtechnologies.com" target="_blank">www.fsrtechnologies.com</a><br>
</div></blockquote>
<br>
Thank you for the suggestion that i should enforce the parantheses. At least that changed the error. Unfortunately that is wierd one, too:<br>
<br>
Traceback &lt;most recent call first&gt;:<br>
   File &quot;insertdb_pg8000.py&quot;, line 20, in &lt;module&gt;<div class="im"><br>
      cursor.execute( (&quot;UPDATE testtable SET jpeg = %s WHERE testtable_n = %s&quot;, data1, data2) )<br>
   File &quot;build\bdist.win32\egg\pg8000\dbapi.py&quot;, line 243, in _fn<br></div>
   File &quot;build\bdist.win32\egg\pg8000\dbapi.py&quot;, line 314, in execute<br>
   File &quot;build\bdist.win32\egg\pg8000\dbapi.py&quot;, line 319, in _execute<br>
   File &quot;build\bdist.win32\egg\pg8000\interface.py&quot;, line 303, in execute<br>
   File &quot;build\bdist.win32\egg\pg8000\interface.py&quot;, line 108, in _init_<br>
   File &quot;build\bdist.win32\egg\pg8000\protocol.py&quot;, line 913, in _fn<br>
   File &quot;build\bdist.win32\egg\pg8000\protocol.py&quot;, line 1048, in parse<br>
UnicodeDecodeError: &#39;ascii&#39; codec can&#39;t decode byte 0xff in position 49: ordinal not in range()<br>
<br>
I mean, as far as i know, for binary files i do not need to set encoding when i open them.<br></blockquote><div><br>OK - when I answered before, I was only looking at the error message and the actual line of code that generated it; I hadn&#39;t really looked at what you&#39;re trying to do.<br>
<br>Now that I&#39;ve stepped back a bit, here&#39;s what I think you&#39;re trying to achieve:<br>- open the file &quot;faqns_osaka_2.jpg&quot;<br>- read its contents<br>- write the contents to a BLOB field (or whatever the Postgres equivalent is - anyway, a field that can hold an arbitrary chunk of data)<br>
- write the name &#39;faqns_osaka_2&#39; to a label field.<br><br>Unfortunately, you&#39;re trying to build the SQL command to do that using string interpolation (the %s notation.)  So your program gets as far as reading the contents of the file, and then tries to decode them into a string  - and that&#39;s why you get this error.  Be happy you got the error - if it had succeeded, the resulting binary data would have been unreadable as an image, and you wouldn&#39;t have known why.<br>
<br>I&#39;m certain that there are proper ways to pass chunks of binary data for insertion into BLOB fields - people must do this every day - but I don&#39;t actually know them. <br><br>Here&#39;s a possibility:<br><a href="http://book.opensourceproject.org.cn/lamp/python/pythoncook2/opensource/0596007973/pythoncook2-chp-7-sect-11.html">http://book.opensourceproject.org.cn/lamp/python/pythoncook2/opensource/0596007973/pythoncook2-chp-7-sect-11.html</a><br>
<br>Or try searching for &quot;python postgres blob&quot;.<br></div></div><br><br clear="all"><br>-- <br><a href="http://www.fsrtechnologies.com">www.fsrtechnologies.com</a><br>