1

我正在尝试使用python中的httplib模块向“www.python.org”发送一个基本的get请求以获取“www.python.org/index.html”。我使用代理服务器“10.1.1.19:80”。显示了带有错误消息的代码。请向我提出我正在犯的错误。问候....

>>> import httplib                  
>>> conn=httplib.HTTPConnection("http://www.python.org",80)                 
>>> conn.set_tunnel("10.1.1.19:80")                                             
>>> conn.request("GET","www.python.org/index.html",headers={"Proxy-Authorization":"Basic "+"MzEwNTMzOmdveWFs"})  




Traceback (most recent call last):                                           
  File "<pyshell#3>", line 1, in <module>                                                 
    conn.request("GET","www.python.org/index.html",headers={"Proxy-Authorization":"Basic "+"MzEwNTMzOmdveWFs"})                                                                   
  File "C:\Python27\lib\httplib.py", line 973, in request                                          
    self._send_request(method, url, body, headers)                                                                                                            
  File "C:\Python27\lib\httplib.py", line 1007, in _send_request
    self.endheaders(body)                                                         
  File "C:\Python27\lib\httplib.py", line 969, in endheaders
    self._send_output(message_body)
  File "C:\Python27\lib\httplib.py", line 829, in _send_output                                     
    self.send(msg)
  File "C:\Python27\lib\httplib.py", line 791, in send
    self.connect()
  File "C:\Python27\lib\httplib.py", line 772, in connect                                 
    self.timeout, self.source_address)                                                      
  File "C:\Python27\lib\socket.py", line 553, in create_connection                                 
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):                                       
gaierror: [Errno 11004] getaddrinfo failed`
4

1 回答 1

3

试试这个

import httplib
conn = httplib.HTTPConnection("10.1.1.19", 80)
conn.request("GET", "http://www.python.org/index.html", headers={...}))
于 2013-08-18T06:41:40.197 回答