Puzzling form/cgi problem

Discussion in 'Python' started by Dfenestr8, Nov 2, 2003.

  1. Dfenestr8

    Dfenestr8 Guest

    Hi.

    I have a problem with a subroutine in a cgi script that's supposed to
    return the byte location at the end of a file, which the script then
    stores as a hidden input on a web form.

    Unfortunately, even though it works fine in the python shell, in the
    cgi-script it always returns "0". That's no use to me at all.

    Here's the subroutine......

    def getLastByteLoc(log):
    #open log file
    f = open(log)

    #seek to end of log file.
    f.seek(0,2)

    location = f.tell()
    f.close()
    return location
     
    Dfenestr8, Nov 2, 2003
    #1
    1. Advertising

  2. Dfenestr8

    Peter Hansen Guest

    Dfenestr8 wrote:
    >
    > I have a problem with a subroutine in a cgi script that's supposed to
    > return the byte location at the end of a file, which the script then
    > stores as a hidden input on a web form.
    >
    > Unfortunately, even though it works fine in the python shell, in the
    > cgi-script it always returns "0". That's no use to me at all.


    Not sure about a fix for the seek() problem, by can't you just use
    os.stat() to get the size of the file?

    -Peter
     
    Peter Hansen, Nov 2, 2003
    #2
    1. Advertising

  3. On Mon, 03 Nov 2003 06:23:24 +1000, "Dfenestr8" <> wrote:

    >Hi.
    >
    >I have a problem with a subroutine in a cgi script that's supposed to
    >return the byte location at the end of a file, which the script then
    >stores as a hidden input on a web form.
    >
    >Unfortunately, even though it works fine in the python shell, in the
    >cgi-script it always returns "0". That's no use to me at all.
    >

    If you want to use that routine, you might want to return something distinctive in case
    of exceptions. E.g., perhaps the cgi prog can't see the file the way you are specifying it
    (is it a full path? Is that legal in the context of the cgi, which are sometimes constrained
    to access down a particular subtree?) or doesn't have adequate permissions (cgi is probably
    running as "nobody" or some other server user id, and running in a different default directory).

    >Here's the subroutine......
    >
    >def getLastByteLoc(log):
    > #open log file
    > f = open(log)
    >
    > #seek to end of log file.
    > f.seek(0,2)
    >
    > location = f.tell()
    > f.close()
    > return location
    >


    Regards,
    Bengt Richter
     
    Bengt Richter, Nov 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard

    puzzling <div> problem

    Richard, Sep 12, 2003, in forum: HTML
    Replies:
    2
    Views:
    383
  2. George Sakkis

    Puzzling OO design problem

    George Sakkis, Apr 9, 2005, in forum: Python
    Replies:
    18
    Views:
    548
    George Sakkis
    Apr 11, 2005
  3. CS ADNT

    Puzzling xsl problem

    CS ADNT, Feb 19, 2010, in forum: ASP .Net
    Replies:
    3
    Views:
    488
    Alexey Smirnov
    Feb 23, 2010
  4. Stefan Fischer
    Replies:
    2
    Views:
    359
    Stefan Fischer
    Feb 23, 2010
  5. richard

    Puzzling problem with code

    richard, Feb 18, 2013, in forum: HTML
    Replies:
    5
    Views:
    488
    Mike Duffy
    Feb 19, 2013
Loading...

Share This Page