Strange MySQL Problem...

Victor Subervi victorsubervi at gmail.com
Thu Apr 3 13:03:53 EDT 2008


On Thu, Apr 3, 2008 at 9:34 AM, Gabriel Genellina <gagsl-py2 at yahoo.com.ar>
wrote:

> En Thu, 03 Apr 2008 09:43:57 -0300, Victor Subervi
> <victorsubervi at gmail.com> escribió:
>
> >> Steve Holden wrote:
> >> Define "no longer works".
> > Sorry. Throws HTTP 200 error.
>
> HTTP 200 means OK.


Yes. But there is an error somewhere, because it doesn´t run all the code.
For example, I have to manually drop the table.


>
>
> >> > The same remarks I've posted earlier apply here.
> > Must have missed those. Yes, the code works fine. Repeatedly.
>
>
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/b732eee4e91b1868/


Thank you. I believe you mean by bound, something like this, right?
binary(picdata)
I am now doing that, if I am not mistaken.


> display or *log* errors...


Yeah. There are always errors...


> *post*? This is the server response. Return either text *or* an image (the
> text may be an html referencing the image)


Yes, post. But what do I write instead of this?
print 'Content-Type: image/jpeg\r\n'


> Test it locally (just the database thing, no web), test the cgi script
> without database interaction, only then join the two.


Okay, but how do I upload an image into mysql without a script? And once I
can do that, everything´s (almost) solved!


> But you can read the server logs at least?


I am new to Plesk. I discovered I can read logs. More following...


>
> Your code is throwing exceptions but you're not seeing them. Use the cgitb
> module http://docs.python.org/lib/module-cgitb.html


Now here you give me another laugh :) I added this line to the script
import cgitb; cgitb.enable()
and suddenly I can take out these junk lines that were throwing the HTTP 200
error:
names = 'aramis', 'athos', 'porthos'
data = {}
for name in names:
  datum = list(name)
  datum.sort()
  data[name] = cPickle.dumps(datum, 1)
Is this some kind of magic wand? :)

Okay, where I am at now...

I have a script called start.py which has this code in it:

import cgitb; cgitb.enable()
import MySQLdb
import struct
import _mysql, sys
Lots of imports, just to try things out. Most not needed...

  col_names = ['id', 'name_en', 'name_es', 'name_it', 'category',
'title_en', 'title_es', 'title_it', \
    'description_en', 'description_es', 'description_it', 'price',
'bedrooms', 'bathrooms', 'pic1', 'sort_factor']
Just notice the pic1 there...
Then I make a nice list of colnames like MySQL wants...

  col_names_with_commas = ''
  for name in col_names:
    col_names_with_commas += name + ', '
  count = len(col_names_with_commas)-2
  col_names_with_commas =
col_names_with_commas[0:len(col_names_with_commas)-2]
All that I have checked, it is good...
Here is the sticky point:

    for id in ids:
      for d in id:
        print '<tr>\n'
        cursor.execute('select ' + col_names_with_commas + ' from products
where id = ' + str(d) + ';')
        col_fields = cursor.fetchall()
        i = 0
        x = 0
        for field in col_fields[0]:
          if x == 0:
            # This is the ID field
            i += 1
            check = 'check' + str(i)
            print '<td><input type="checkbox" name="', check, '" value="',
field, '" /></td>\n'
          if x == 15:
            print '<td>', field, '</td>\n'
          else:
            print '<td>', field, '</td>\n'
          x += 1
I have to do both of those for statements. The sticky point is in the last
if statement. 15 is the pic1 field. Should I use binary(field) instead? It
does not like that.

I send the whole thing over to another script which has this:

import cgitb; cgitb.enable()
import MySQLdb
import cgi
import struct
Same old same old...
Here´s the sticky part...

  if what_do == 'insert':
    data = ['', '', '', '', '', '', '', '', '', '', '', 0.0, '', '', '',
500]
    the_form(data, what_do)
  elif what_do == 'update':
    cursor.execute('select * from products where id=' + update_these[0] +
';')
    data = cursor.fetchall()
    the_form(data[0], what_do)
And then try to render...

<td>
1ra Foto Grande:
</td><td>
<input type='file' name='pic1' value="""
  print '"', binary(data[14]), '"'
  print """
/>
I show you both parts, because the Internal Server Error comes from the
second page, but the logged error points to the first page. Here is the log
record...

[Thu Apr 03 09:53:33 2008] [error] [client 190.166.0.65] PythonHandler
mod_python.cgihandler: File "/var/www/vhosts/
livestocksling.com/httpdocs/test/python/Shop/iud.py", line 210, in
the_form\n print '"', binary(data[14]), '"', referer:
http://livestocksling.com/test/python/Shop/start.py
[Thu Apr 03 09:53:33 2008] [error] [client 190.166.0.65] PythonHandler
mod_python.cgihandler: NameError: global name 'binary' is not defined,
referer: http://livestocksling.com/test/python/Shop/start.py
TIA,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080403/99291d60/attachment-0001.html>


More information about the Python-list mailing list