3

The following code throws an error "socket.gaierror: [Errno -2] Name or service not known".

import httplib, urllib
attrs = urllib.urlencode({"username":"admin", "password":"admin"})
conn = httplib.HTTPSConnection("https://x.x.x.x:8181")
conn.request("POST", "/login", attrs)
response = conn.getresponse()
print response.status, response.reason

I don't want to use urllib2 module. Could anybody help me?... How to save the state of that server?, so that next time i directly post the values for the uri.

ameet
  • 31
  • 2

3 Answers3

1

I think you are not specifying the non-default port correctly: http://docs.python.org/release/2.6.7/library/httplib.html#httplib.HTTPSConnection

Try this instead:

   conn = httplib.HTTPSConnection("https://x.x.x.x",port=8181)
Uku Loskit
  • 40,868
  • 9
  • 92
  • 93
0

I was getting a similar error with httplib.HTTPConnection, I found changing the url from "http://x.x.x.x" to "x.x.x.x" worked for me. Try removing the "http://" or "https://".

conn = httplib.HTTPSConnection("x.x.x.x:8181")
Allan5
  • 351
  • 5
  • 17
0

Try the following code:

conn = httplib.HTTPSConnection("x.x.x.x",port=8181)
apaderno
  • 28,547
  • 16
  • 75
  • 90
Jolanda Verhoef
  • 609
  • 5
  • 11