|
From: Thomas S. <t.s...@fz...> - 2009-11-16 16:08:35
|
you're right, there are no 'separate ways' (i first thought the
'Content-Type' lines would go somewhere else than the gnuplot
output, but that's not the case).
both, the print commands and gnuplots output go through stdout - but,
i just ran your little script and realized that the 'Content-Type' lines are
at the end.
you can reproduce this by running your script in a terminal and
piping the output into a file.
you need a 'flush' after 'print'ing the two lines:
#!/usr/bin/python
import os
import sys
import math
print "Content-Type: image/png" # This is an image
print # blank line, end of headers
sys.stdout.flush();
gp = os.popen("/usr/bin/gnuplot", 'w')
gp.write("set term png;set o;")
gp.write("plot '-' u 1:2 w linesp\n")
xs = [a/10.0 for a in range(0,101,1)]
for x in xs:
y = x * math.sin(x)
gp.write( "%f %f\n" % (x, y))
gp.write("e\n")
gp.close()
stevecoh1 wrote:
>
> OK, I feel like an idiot but I guess I'm really not understanding you
> even after reading the document you referred me to. The specific words
> I'm not understanding are "going separate ways".
>
> To that end I've gone back to basics and rewritten the example on p. 241
> in python. I believe my translation is more or less exact:
>
> ================================
> #!/usr/bin/python
>
> import os
> import math
>
> print "Content-Type: image/png" # This is an image
> print # blank line, end of headers
>
> gp = os.popen("/usr/bin/gnuplot", 'w')
> gp.write("set term png;set o;")
> gp.write("plot '-' u 1:2 w linesp\n")
>
> xs = [a/10.0 for a in range(0,101,1)]
> for x in xs:
> y = x * math.sin(x)
> gp.write( "%f %f\n" % (x, y))
> gp.write("e\n")
> gp.close()
>
>
>
> =================================
>
> This fails with the following message
> [error] [client ::1] malformed header from script. Bad header=\x89PNG:
>
> whether or not the gp.close() line is commented out.
>
> What am I missing?
>
>
>
>
>
> Thomas Sefzick wrote:
>> seems that your header:
>>
>> print "Content-Type: image/png" # This is an image
>> print # blank line, end of headers
>>
>> and gnuplots output (png graphics) are going different
>> ways, because the png graphics is sent without header
>> (a png file starts with "\x89PNG").
>>
>> have a look at the section "Object Headers" in
>> http://marc.merlins.org/htmlearn/misc/cgi-faq.txt
>>
>>
>> stevecoh1 wrote:
>>> Here's the error:
>>>
>>> [error] [client ::1] malformed header from script. Bad header=\x89PNG:
>>> usage_graph.cgi
>>>
>
> ...
>
>
>
> ------------------------------------------------------------------------------
> 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
>
>
--
View this message in context: http://old.nabble.com/strange-behavior-on-calling-gnuplot-from-cgi-script-written-in-python-tp26356744p26374508.html
Sent from the Gnuplot - User mailing list archive at Nabble.com.
|