import of 'string' fails in CGI-BIN script...but works in IDLE

Discussion in 'Python' started by John F Dutcher, Dec 2, 2003.

  1. Having 'cloned' an existing python script that imports 'string' and
    uses "string.rstrip()" without incident...
    I am at a loss to explain why the new 'cloned' script (brief sample
    below) continually errors with:
    NameError: global name 'string' is not defined
    args = ("global name 'string' is not defined",)

    when run from the server CGI-BIN.

    If the same script is run in 'IDLE' it
    works with no problem. Yet, the "import urllib, string" statement is
    clearly
    present in the script.

    I am running Python 2.3.1 on Win 95, using XITAMI as the server.

    Troublesome script follows:

    #!c:\Python\python.exe
    import cgitb; cgitb.enable()
    import traceback, sys, os, cgi
    import urllib, string
    sys.stderr = sys.stdout
    form = cgi.FieldStorage()
    def writeHTML(rec):
    print "Content-Type: text/html"
    print
    print '''
    <FORM ACTION="/cgi-bin/dietsys7.py" METHOD="POST">
    <CENTER>
    <B><INPUT TYPE="SUBMIT" VALUE="Click to Apply Changes"></B><br><br>'''
    print '''
    <TABLE BORDER=1 BGCOLOR="FFFF99">'''
    cycle = 1
    drptr = 7
    for x in range(10):
    uvalue = string.rstrip(rec[drptr]) <-----(** failure occurs
    here)
    if not ((cycle % 2) == 0):
    print '''<TR bgcolor="pink"><td>'''
    else:
    print '''<TR bgcolor="yellow"><td>'''
    print '''<INPUT TYPE="text" NAME=''' + '"' + 'doctorcode' +
    str(cycle) + '"' + ' ' + '''size="36" maxlength="1" value=''' + '"' +
    uvalue + '"' + ' ' + '''>'''
    print '''<td><b>Doctor Color Code</B></td></tr>'''
    cycle = cycle + 1
    drptr = drptr + 1
    print '''</table></FORM></FONT></BODY></HTML>'''
    fileName = os.path. join("c:", "/xitami", "cgi-bin", "dsysmst.dat")
    #print 'Globals: ' + str(globals())
    #print 'Locals: ' + str(locals())
    f = open(fileName, 'rb')
    f.seek(-2690,2)
    recd = f.read(2690)
    if recd[3:7] == '0000':
    f.close()
    writeHTML(recd)
    sys.exit()
    else:
    print "Did not get utility record"
    f.close()
    sys.exit()
     
    John F Dutcher, Dec 2, 2003
    #1
    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. Kevin Mitchell

    Can "bin" be changed to "cgi-bin" for asp.net

    Kevin Mitchell, Oct 19, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,028
    Wim Hollebrandse
    Oct 19, 2003
  2. Bill Davy
    Replies:
    0
    Views:
    739
    Bill Davy
    May 12, 2005
  3. John Boy
    Replies:
    1
    Views:
    331
    John Machin
    Mar 10, 2008
  4. anne001
    Replies:
    1
    Views:
    591
  5. Randell D.
    Replies:
    7
    Views:
    178
    Randell D.
    Oct 26, 2003
Loading...

Share This Page