Why won't this POST
Sunit Joshi
sjoshi at ingr.com
Tue Apr 23 00:47:44 EDT 2002
Hello
I'm trying to post data to IIS5.0 but keep getting error message about
"host not found". The python script is in /cgi-bin/ProcessInput.py. I
can connect to the host but cannot execute the script.
Here's the error message:
Will POST 43 bytes: txtName=guest&txtPwd=guest&txtPyInput=login
Traceback (most recent call last):
File "C:\Sunit\Web\eubix\eubix_Local\cgi-bin\postTest.py", line 17,
in ?
req.putrequest('POST' ,'/cgi-bin/ProcessInput.py')
File "C:\Python21\lib\httplib.py", line 437, in putrequest
self.send(str)
File "C:\Python21\lib\httplib.py", line 379, in send
self.connect()
File "C:\Python21\lib\httplib.py", line 363, in connect
self.sock.connect((self.host, self.port))
File "<string>", line 1, in connect
socket.error: host not found
Here's the postTest.py script
from httplib import HTTP
from urllib import quote
quoteUsername = 'guest'
quotePwd = 'guest'
quoteInput = 'login'
postData = 'txtName=' + quote(quoteUsername) + '&txtPwd=' \
+ quote(quotePwd) + '&txtPyInput=' + quote(quoteInput)
print 'Will POST ', str(len(postData)) + ' bytes:', postData
# begin HTTP request
req = HTTP('localhost/eubix')
#req.putrequest("GET" ,'/PyCgi/formTest.py?' + postData)
req.putrequest('POST' ,'/cgi-bin/ProcessInput.py') #Here's where it
stalls
req.putheader("Accept", "text/html")
req.putheader("User-Agent", "postTest.py")
# Need this otherwise Only GET works
req.putheader("Content-type", "application/x-www-form-urlencoded")
# Set Content-length to length of PostData
req.putheader("Content-length", str(len(postData)))
req.endheaders()
# Send POST data after ending headers
req.send(postData)
replycode, message, headers = req.getreply()
print "HTTP RESPONSE: ", replycode, message
print 'HEADERS: ', str(headers)
# Get file-like object from HTTP response
# and print received HTML to screen.
fd = req.getfile()
txtlines = fd.read()
fd.close()
print '\nReceived following HTML:\n'
print txtlines
thanks
Sunit
sjoshi at ingr.com
More information about the Python-list
mailing list