Fileupload over CGI simulate
Will Stuyvesant
hwlgw at hotmail.com
Wed Jan 29 03:05:56 EST 2003
Marian Förster <marian.foerster at informatik.tu-chemnitz.de> wrote in message news:<3E373968.9020804 at informatik.tu-chemnitz.de>...
> Hallo!
>
> I want to do a fileupload to a cgi over python, not over the browser.
>
> Are there an example??
I do not have a complete example for your problem. But I have this
callcgi.py module that shows a way to call a CGI script from python.
You would need a way to pass the file to the script so its sent with
POST, not sure how to do that...
----- callcgi.py -----------------------------------------------------
import urllib
import sys
def usage():
print """
Usage: callcgi.py url_with_cgi_script
If url_with_cgi_script is omitted then
"http://localhost:8000/cgi-bin/test.py"
is taken.
"""
# get a fileobject fp for access to the cgi script
if len(sys.argv) < 2:
fp = urllib.urlopen(r'http://localhost:8000/cgi-bin/test.py')
else:
if sys.argv[1][0] in ['-','/','\\']:
usage()
sys.exit()
fp = urllib.urlopen(sys.argv[1])
# read data from the cgi script and put the data in result
n = 0
result = ''
while 1:
s = fp.read(8192)
if not s: break
result = result + s
n = n + len(s)
fp.close()
# show what happened and show headers
print '----- callcgi.py -----'
print 'copied', n, 'bytes from', fp.url
for k,v in fp.headers.items():
print k, '=', v
# show the data the cgi script returns
print
print result
More information about the Python-list
mailing list