Puzzling form/cgi problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dfenestr8

    Puzzling form/cgi problem

    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

  • Peter Hansen

    #2
    Re: Puzzling form/cgi problem

    Dfenestr8 wrote:[color=blue]
    >
    > 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.[/color]

    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

    Comment

    • Bengt Richter

      #3
      Re: Puzzling form/cgi problem

      On Mon, 03 Nov 2003 06:23:24 +1000, "Dfenestr8" <chrisdewinN0SP AM@yahoo.com.au > wrote:
      [color=blue]
      >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.
      >
      >Unfortunatel y, 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.
      >[/color]
      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).
      [color=blue]
      >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
      >[/color]

      Regards,
      Bengt Richter

      Comment

      Working...