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.

asked Aug 19, 2011 at 8:12
2
  • can you manually resolve the address? Commented Aug 19, 2011 at 8:16
  • Yes, I can manually resolve the address. The above thing working fine with urllib2 module. But the need to use httplib. Commented Aug 19, 2011 at 8:20

3 Answers 3

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)
answered Aug 19, 2011 at 8:18
Sign up to request clarification or add additional context in comments.

Comments

0

Try the following code:

conn = httplib.HTTPSConnection("x.x.x.x",port=8181)
avpaderno
30k17 gold badges81 silver badges95 bronze badges
answered Nov 8, 2011 at 11:57

Comments

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")
answered Jun 18, 2012 at 1:57

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.