FAQ
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

Search Discussions

  • Miki at Mar 5, 2008 at 3:51 pm
    Hello Rod,
    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 at gmail.com>
    http://pythonwise.blogspot.com
  • Rodmc at Mar 6, 2008 at 9:37 am
    Hi,

    Good point, some code samples is probably required. Please note that
    for reasons of integration with another system I am not using a
    templating system.


    Anyway I have copied them below:

    Python:

    f = open("finish.html")
    doc = f.read()
    f.close()
    print doc


    HTML:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html;
    charset=windows-1252">
    <TITLE></TITLE>
    </HEAD>
    <BODY LANG="en-GB" DIR="LTR">
    <P><IMG SRC="banner.jpg" NAME="graphics1" ALIGN=LEFT WIDTHy9
    HEIGHT7 BORDER=0><BR CLEAR=LEFT><BR><BR>
    </P>
    <P>Thank you for uploading your file</P>
    </BODY>
    </HTML>
  • Bryan Olson at Mar 6, 2008 at 10:46 am
    rodmc wrote:
    [...]
    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?
    HTML: [...]
    <P><IMG SRC="banner.jpg" NAME="graphics1" ALIGN=LEFT WIDTHy9
    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 at Mar 6, 2008 at 11:43 am
    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 wrote:
    rodmc wrote:

    [...]
    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?
    HTML: [...]
    <P><IMG SRC="banner.jpg" NAME="graphics1" ALIGN=LEFT WIDTHy9
    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 at Mar 6, 2008 at 8:05 pm

    rodmc wrote:
    [...] 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/Cookbook/Python/Recipe/550822


    --
    --Bryan
  • Rodmc at Mar 8, 2008 at 7:40 pm

    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.

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

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/550822
    Thanks, I will try this.

    Rod

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMar 5, '08 at 2:47p
activeMar 8, '08 at 7:40p
posts7
users3
websitepython.org

3 users in discussion

Rodmc: 4 posts Bryan Olson: 2 posts Miki: 1 post

People

Translate

site design / logo © 2022 Grokbase