Hi!
Just came across one more problem. Any idea how to go about this one?
In the GPRS section of the app I am building, I send some data to a specific url. The code (which works fine on the computer) is rather simple -
Code:
import httplib, urllib
params = urllib.urlencode({'test': 1})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("sahyadrians.110mb.com:80")
conn.request("POST", "/home.html", params, headers)
response = conn.getresponse()
print response.status, response.reason
# 200 OK
data = response.read()
conn.close()
This code works fine, both on the phone as well as on the computer. Now, if the server is down or the url (in conn.request) is wrong, one would expect to get a simple error from this script saying -
However, when I tweaked the code (and gave a non-legitimate site) -
Code:
import httplib, urllib
params = urllib.urlencode({'test': 1})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("sahyadrians.110mb.com:80")
conn.request("POST", "/non_existent_page.html", params, headers)
response = conn.getresponse()
print response.status, response.reason
# 200 OK
data = response.read()
conn.close()
I got the following errors -
Traceback (most recent call last)
File "<console>", line 1, in ?
File "c:\resource\httplib.py",line 459, in request
self._send_request(method, url, body, headers)
File "c:\resource\httplib.py", line 470, in send_request
self.putrequest(method,url)
File "c:\resource\httplib.py", line 415, in putrequest
raise CannotSendRequest
Any idea why the code does not give me the (expected) 404 error? When I try the same in the emulator, I get the "404 Not Found" error (like expected)
I tried using something like -
try:
conn.request("POST", "/non_existent_page.html", params, headers)
except ValueError:
print "Error"
But it still throws an error.
Any help would be super! Please...
Thanks