使用conn = httplib.HTTPConnection时出错(“http:// ipaddr:port”)

时间:2012-08-06 22:14:25

标签: python http

我正在使用

httplib.HTTPConnection ("http://ipaddr:port")  
conn.request("GET", "", params, headers)

我可以使用我的firefox客户端使用ipaddr:port进行PUT / GET !! 但是我在执行脚本时看到了这个错误:

 File "post_python.py", line 5, in <module>
    conn.request("GET", "", params, headers)
  File "/usr/lib64/python2.6/httplib.py", line 914, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib64/python2.6/httplib.py", line 951, in _send_request
    self.endheaders()
  File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders
    self._send_output()
  File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output
    self.send(msg)
  File "/usr/lib64/python2.6/httplib.py", line 739, in send
    self.connect()
  File "/usr/lib64/python2.6/httplib.py", line 720, in connect
    self.timeout)
  File "/usr/lib64/python2.6/socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known"

请有人帮助我吗?

3 个答案:

答案 0 :(得分:2)

您可能在浏览器之间已经知道了代理。如果您在linux下,请尝试设置http_proxy环境变量。

答案 1 :(得分:2)

尝试此操作(在IP地址前没有“http://”):

conn = httplib.HTTPConnection("x.x.x.x", port)  
conn.request("GET", "", params, headers)

答案 2 :(得分:0)

如果是IPv6地址,则需要根据RFC 2732用括号括起来。如果我没记错的话,如果你不使用括号,那就是你得到的错误信息。

httplib.HTTPConnection ("http://[::1]:8080")  
conn.request("GET", "", params, headers)