Connecting Tech Pros Worldwide Forums | Help | Site Map

Python CGI & Webpage with an Image

rodmc
Guest
 
Posts: n/a
#1: Mar 5 '08
Hi,

I have a set of CGI scripts set up and in one page (which is stored in
an HTML file then printed via a python CGI) there is an image. However
the image never displays, can anyone recommend a way round this
problem?

Kind regards,

rod

Miki
Guest
 
Posts: n/a
#2: Mar 5 '08

re: Python CGI & Webpage with an Image


Hello Rod,
Quote:
I have a set of CGI scripts set up and in one page (which is stored in
an HTML file then printed via a python CGI) there is an image. However
the image never displays, can anyone recommend a way round this
problem?
We need more information, can you post a code snippet? error page? ...

My *guess* is that the web server don't know how to server the image
(wrong path configuration?)

HTH,
--
Miki <miki.tebeka@gmail.com>
http://pythonwise.blogspot.com

Bryan Olson
Guest
 
Posts: n/a
#3: Mar 6 '08

re: Python CGI & Webpage with an Image


rodmc wrote:
[...]
Quote:
Python:
>
f = open("finish.html")
doc = f.read()
f.close()
print doc
You might need to start with:

print "Content-Type: text/html"
print

Is "finish.html" in the right place? When you browse to your
script, can you see that you're getting the html?
Quote:
HTML:
[...]
Quote:
<P><IMG SRC="banner.jpg" NAME="graphics1" ALIGN=LEFT WIDTH=799
I suspect a server configuration and/or resource placement problem.
The image has a relative URL, and the user's browser will look for
it on the same path that it used to get the resource served by the
cgi script, up to last '/'.

Is banner.jpg in the right place, and is your web server configured
to treat everything in that directory as a cgi script, and thus
trying to execute the jpg? If one of those is the problem, just
move banner.jpg, and/or change the relative URL. For example,
SRC="../banner.jpg" will cause the browser to look for the jpg
one directory above.

Failing that, can look at the web server's log?

--
--Bryan
rodmc
Guest
 
Posts: n/a
#4: Mar 6 '08

re: Python CGI & Webpage with an Image


Hi,

Thanks for your very quick response. I have played around a bit more
so that both the image and HTML file are in the public_html folder.
They are called via python using a relative URL, and have permissions
set to 755. Within the HTML file the image is accessed using just
"banner.jpg". The actual page displays ok except for the image - so it
has the same problem as before. However when the same page is
displayed without running through a CGI it displays perfectly.

Kind regards,

rod

On Mar 6, 11:46 am, Bryan Olson <fakeaddr...@nowhere.orgwrote:
Quote:
rodmc wrote:
>
[...]
Quote:
Python:
>
f = open("finish.html")
doc = f.read()
f.close()
print doc
>
You might need to start with:
>
print "Content-Type: text/html"
print
>
Is "finish.html" in the right place? When you browse to your
script, can you see that you're getting the html?
>
Quote:
HTML:
[...]
Quote:
<P><IMG SRC="banner.jpg" NAME="graphics1" ALIGN=LEFT WIDTH=799
>
I suspect a server configuration and/or resource placement problem.
The image has a relative URL, and the user's browser will look for
it on the same path that it used to get the resource served by the
cgi script, up to last '/'.
>
Is banner.jpg in the right place, and is your web server configured
to treat everything in that directory as a cgi script, and thus
trying to execute the jpg? If one of those is the problem, just
move banner.jpg, and/or change the relative URL. For example,
SRC="../banner.jpg" will cause the browser to look for the jpg
one directory above.
>
Failing that, can look at the web server's log?
>
--
--Bryan


Bryan Olson
Guest
 
Posts: n/a
#5: Mar 6 '08

re: Python CGI & Webpage with an Image


rodmc wrote:
Quote:
[...] I have played around a bit more
so that both the image and HTML file are in the public_html folder.
They are called via python using a relative URL, and have permissions
set to 755. Within the HTML file the image is accessed using just
"banner.jpg". The actual page displays ok except for the image - so it
has the same problem as before. However when the same page is
displayed without running through a CGI it displays perfectly.
Is the cgi script in the same directory? The user's browser looks
for the jpg relative to the URL it used to get the page, which in
the case of the CGI script is the path to the script, not the
path to the html file.

If server logs are hard to get or read, try my runcgi.py script:

http://aspn.activestate.com/ASPN/Coo.../Recipe/550822


--
--Bryan
rodmc
Guest
 
Posts: n/a
#6: Mar 8 '08

re: Python CGI & Webpage with an Image


Quote:
Is the cgi script in the same directory? The user's browser looks
for the jpg relative to the URL it used to get the page, which in
the case of the CGI script is the path to the script, not the
path to the html file.

No the CGI script is in a different folder, I could move everything to
the same folder I guess.

Quote:
If server logs are hard to get or read, try my runcgi.py script:
>
http://aspn.activestate.com/ASPN/Coo.../Recipe/550822
Thanks, I will try this.

Rod
Closed Thread