|
From: Steve C. <sc...@ja...> - 2009-11-15 16:59:21
|
Here's the error:
[error] [client ::1] malformed header from script. Bad header=\x89PNG:
usage_graph.cgi
I don't understand this. How could closing the gnuplot process create a
malformed header yet leaving it open produces usable output? Still, I
guess that's a clue. I just don't know what it means.
Here is the guts of the script, deliberately leaving out details:
#!/usr/bin/python
import cgi
import MySQLdb
import os
parms = cgi.FieldStorage()
print "Content-Type: image/png" # This is an image
print # blank line, end of headers
# open database connection
...
# create a cursor
cursor = db.cursor()
# execute SQL query
cursor.execute(query % (userid))
# get the resultset as a tuple
result = cursor.fetchall()
...
# open gnuplot process
gp = os.popen("/usr/bin/gnuplot, 'w')
# initialize the plot with desired settings including definition of
# "weekday" function.
...
# send plot command to gnuplot process
gp.write("""plot '-' u 1:(weekday(timecolumn(1)) ? column(2) : 0/0) ti
"Weekday" w impulses, \
'' u 1:(weekday(timecolumn(1)) ? column(2) : 0/0) ti "Weekend" w
impulses\n""")
# send data to the plot command
for record in result:
gp.write("%s %2.3f %d\n" % record)
gp.write("e\n")
#bombs out if following is uncommented.
#gp.close()
Again, I can't see anything here that would work if the gnuplot process
was left open but fail if it is closed.
Thomas Sefzick wrote:
> there should be information about what caused the error in
> the error-log of the http-server.
>
>
> stevecoh1 wrote:
>> Am trying to use gnuplot as a subprocess to a CGI script written in
>> python (similar to the perl script on p. 241 of "Gnuplot in Action").
>>
>> The python script itself follows the pattern of the python script on
>> p.230-231, that is
>>
>> gp = os.popen( ' /usr/bin/gnuplot', 'w')
>> ... plotting commands
>> gp.close()
>>
>> The cgi script produces a 500 error.
>>
>> But, if I comment out the gp.close() command, it works perfectly, and
>> produces the graph I want. What is going on here?
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment - and focus
>> on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Gnuplot-info mailing list
>> Gnu...@li...
>> https://lists.sourceforge.net/lists/listinfo/gnuplot-info
>>
>>
>
|