连接尝试失败,因为连接方在一段时间后没有正确响应或连接的主机未能响应99

时间:2017-07-12 05:08:07

标签: python request urllib2 urllib3

我已经尝试了很多方法来阅读内容或使用Python 3.5从其他网站提取背景HTML。

我熟悉使用HTTP PROXY,我在Windows Server 2008 r2上开发我的项目,这是该公司的政策。

以下是我可以请求连接到其他网站的简单代码。

 import requests
 r = requests.get("https://stackoverflow.com", 
             proxies={"http": "http://proxy.com:900"})
 print(r.text)
  

当我将网址更改为谷歌网址时,它的工作

r = requests.get("https://www.google.com", 
             proxies={"http": "http://proxy.com:900"})

当我使用其他网站的网址时。

然后,我在输出中出现了这个错误。

  C:\Python35\python.exe C:/Users/mwirzonw/PycharmProjects/untitled/test.py
  Traceback (most recent call last):
  File "C:\Python35\lib\site-packages\urllib3\connection.py", line 141, in 
 _new_conn
 (self.host, self.port), self.timeout, **extra_kw)
 File "C:\Python35\lib\site-packages\urllib3\util\connection.py", line 83, 
 in create_connection
 raise err
 File "C:\Python35\lib\site-packages\urllib3\util\connection.py", line 73, 
 in create_connection
 sock.connect(sa)
 TimeoutError: [WinError 10060] A connection attempt failed because the 
 connected party did not properly respond after a period of time, or 
 established connection failed because connected host has failed to respond

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
 File "C:\Python35\lib\site-packages\urllib3\connectionpool.py", line 600, 
 in urlopen
 chunked=chunked)
 File "C:\Python35\lib\site-packages\urllib3\connectionpool.py", line 345, 
 in _make_request
 self._validate_conn(conn)
 File "C:\Python35\lib\site-packages\urllib3\connectionpool.py", line 844, 
 in 
 _validate_conn
 conn.connect()
 File "C:\Python35\lib\site-packages\urllib3\connection.py", line 284, in 
 connect
 conn = self._new_conn()
 File "C:\Python35\lib\site-packages\urllib3\connection.py", line 150, in 
 _new_conn
 self, "Failed to establish a new connection: %s" % e)
 urllib3.exceptions.NewConnectionError: 
 <urllib3.connection.VerifiedHTTPSConnection object at 0x0000000003694390>: 
 Failed to establish a new connection: [WinError 10060] A connection attempt 
 failed because the connected party did not properly respond after a period 
 of time, or established connection failed because connected host has failed 
 to respond

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
 File "C:\Python35\lib\site-packages\requests\adapters.py", line 440, in 
 send
 timeout=timeout
 File "C:\Python35\lib\site-packages\urllib3\connectionpool.py", line 649, 
 in urlopen
 _stacktrace=sys.exc_info()[2])
 File "C:\Python35\lib\site-packages\urllib3\util\retry.py", line 388, in 
 increment
 raise MaxRetryError(_pool, url, error or ResponseError(cause))
 urllib3.exceptions.MaxRetryError: 
 HTTPSConnectionPool(host='stackoverflow.com', port=443): Max retries 
 exceeded with url: / (Caused by 
 NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 
 0x0000000003694390>: Failed to establish a new connection: [WinError 10060] 
 A 
 connection attempt failed because the connected party did not properly 
 respond 
 after a period of time, or established connection failed because connected 
 host has failed to respond',))

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
  File "C:/Users/mwirzonw/PycharmProjects/untitled/test.py", line 4, in 
  <module>
  proxies={"http": "http://proxy.com:9"})
 File "C:\Python35\lib\site-packages\requests\api.py", line 72, in get
   return request('get', url, params=params, **kwargs)
  File "C:\Python35\lib\site-packages\requests\api.py", line 58, in request
   return session.request(method=method, url=url, **kwargs)
  File "C:\Python35\lib\site-packages\requests\sessions.py", line 502, in 
  request
  resp = self.send(prep, **send_kwargs)
  File "C:\Python35\lib\site-packages\requests\sessions.py", line 612, in 
  send
  r = adapter.send(request, **kwargs)
  File "C:\Python35\lib\site-packages\requests\adapters.py", line 504, in 
  send
   raise ConnectionError(e, request=request)
   requests.exceptions.ConnectionError: 
   HTTPSConnectionPool(host='stackoverflow.com', port=443): Max retries 
   exceeded with url: / (Caused by 
   NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 
   0x0000000003694390>: Failed to establish a new connection: [WinError 
   10060] A connection attempt failed because the connected party did not 
   properly respond after a period of time, or established connection failed 
   because connected host has failed to respond',))

   Process finished with exit code 1

我真的需要谁阅读这篇文章的帮助。因为我是python的新手,我尝试了很多方法。

  

我已尝试使用urllib2,urllib3,使用基于此帖子的请求 - Using an HTTP PROXY - Python

但仍然得到相同的输出。

谢谢....

0 个答案:

没有答案