Python 仅对一个特定网站请求错误:操作系统错误10054连接中止

Python 仅对一个特定网站请求错误:操作系统错误10054连接中止,python,python-requests,urllib2,Python,Python Requests,Urllib2,我只在这个网站上看到这个错误 我在谷歌上搜索并阅读了所有内容,但没有一个解决了我的问题 非常简单的一段代码,任何人都能知道发生了什么吗?其他网站运行良好 import requests url = 'http://www.trading212.com/en/Trading-Instruments?id=3' response = requests.get(url) 错误代码: ---------------------------------------------------------

我只在这个网站上看到这个错误

我在谷歌上搜索并阅读了所有内容,但没有一个解决了我的问题

非常简单的一段代码,任何人都能知道发生了什么吗?其他网站运行良好

import requests

url = 'http://www.trading212.com/en/Trading-Instruments?id=3'

response = requests.get(url)
错误代码:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    671                 headers=headers,
--> 672                 chunked=chunked,
    673             )

~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    420                     # Otherwise it looks like a bug in the code.
--> 421                     six.raise_from(e, None)
    422         except (SocketTimeout, BaseSSLError, SocketError) as e:

~\Anaconda3\lib\site-packages\urllib3\packages\six.py in raise_from(value, from_value)

~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    415                 try:
--> 416                     httplib_response = conn.getresponse()
    417                 except BaseException as e:

~\Anaconda3\lib\http\client.py in getresponse(self)
   1320             try:
-> 1321                 response.begin()
   1322             except ConnectionError:

~\Anaconda3\lib\http\client.py in begin(self)
    295         while True:
--> 296             version, status, reason = self._read_status()
    297             if status != CONTINUE:

~\Anaconda3\lib\http\client.py in _read_status(self)
    256     def _read_status(self):
--> 257         line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    258         if len(line) > _MAXLINE:

~\Anaconda3\lib\socket.py in readinto(self, b)
    588             try:
--> 589                 return self._sock.recv_into(b)
    590             except timeout:

~\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in recv_into(self, *args, **kwargs)
    317             else:
--> 318                 raise SocketError(str(e))
    319         except OpenSSL.SSL.ZeroReturnError:

OSError: (10054, 'WSAECONNRESET')

During handling of the above exception, another exception occurred:

ProtocolError                             Traceback (most recent call last)
~\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    448                     retries=self.max_retries,
--> 449                     timeout=timeout
    450                 )

~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    719             retries = retries.increment(
--> 720                 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
    721             )

~\Anaconda3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    399             if read is False or not self._is_method_retryable(method):
--> 400                 raise six.reraise(type(error), error, _stacktrace)
    401             elif read is not None:

~\Anaconda3\lib\site-packages\urllib3\packages\six.py in reraise(tp, value, tb)
    733             if value.__traceback__ is not tb:
--> 734                 raise value.with_traceback(tb)
    735             raise value

~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    671                 headers=headers,
--> 672                 chunked=chunked,
    673             )

~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    420                     # Otherwise it looks like a bug in the code.
--> 421                     six.raise_from(e, None)
    422         except (SocketTimeout, BaseSSLError, SocketError) as e:

~\Anaconda3\lib\site-packages\urllib3\packages\six.py in raise_from(value, from_value)

~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    415                 try:
--> 416                     httplib_response = conn.getresponse()
    417                 except BaseException as e:

~\Anaconda3\lib\http\client.py in getresponse(self)
   1320             try:
-> 1321                 response.begin()
   1322             except ConnectionError:

~\Anaconda3\lib\http\client.py in begin(self)
    295         while True:
--> 296             version, status, reason = self._read_status()
    297             if status != CONTINUE:

~\Anaconda3\lib\http\client.py in _read_status(self)
    256     def _read_status(self):
--> 257         line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    258         if len(line) > _MAXLINE:

~\Anaconda3\lib\socket.py in readinto(self, b)
    588             try:
--> 589                 return self._sock.recv_into(b)
    590             except timeout:

~\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in recv_into(self, *args, **kwargs)
    317             else:
--> 318                 raise SocketError(str(e))
    319         except OpenSSL.SSL.ZeroReturnError:

ProtocolError: ('Connection aborted.', OSError("(10054, 'WSAECONNRESET')"))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
<ipython-input-2-c162877d446b> in <module>
      1 url = 'http://www.trading212.com/en/Trading-Instruments?id=3'
----> 2 response = requests.get(url)

~\Anaconda3\lib\site-packages\requests\api.py in get(url, params, **kwargs)
     74 
     75     kwargs.setdefault('allow_redirects', True)
---> 76     return request('get', url, params=params, **kwargs)
     77 
     78 

~\Anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
     59     # cases, and look like a memory leak in others.
     60     with sessions.Session() as session:
---> 61         return session.request(method=method, url=url, **kwargs)
     62 
     63 

~\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    528         }
    529         send_kwargs.update(settings)
--> 530         resp = self.send(prep, **send_kwargs)
    531 
    532         return resp

~\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
    663 
    664         # Resolve redirects if allowed.
--> 665         history = [resp for resp in gen] if allow_redirects else []
    666 
    667         # Shuffle things around if there's history.

~\Anaconda3\lib\site-packages\requests\sessions.py in <listcomp>(.0)
    663 
    664         # Resolve redirects if allowed.
--> 665         history = [resp for resp in gen] if allow_redirects else []
    666 
    667         # Shuffle things around if there's history.

~\Anaconda3\lib\site-packages\requests\sessions.py in resolve_redirects(self, resp, req, stream, timeout, verify, cert, proxies, yield_requests, **adapter_kwargs)
    243                     proxies=proxies,
    244                     allow_redirects=False,
--> 245                     **adapter_kwargs
    246                 )
    247 

~\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
    641 
    642         # Send the request
--> 643         r = adapter.send(request, **kwargs)
    644 
    645         # Total elapsed time of the request (approximately)

~\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    496 
    497         except (ProtocolError, socket.error) as err:
--> 498             raise ConnectionError(err, request=request)
    499 
    500         except MaxRetryError as e:

ConnectionError: ('Connection aborted.', OSError("(10054, 'WSAECONNRESET')"))
---------------------------------------------------------------------------
OSError回溯(最近一次调用上次)
urlopen中的~\Anaconda3\lib\site packages\urllib3\connectionpool.py(self、method、url、body、headers、retries、redirect、assert\u same\u host、timeout、pool\u timeout、release\u conn、chunked、body\u pos、**response\u kw)
671页眉=页眉,
-->672分块=分块,
673             )
请求中的~\Anaconda3\lib\site packages\urllib3\connectionpool.py(self、conn、方法、url、超时、分块、**httplib\u请求)
420#否则它看起来像是代码中的一个bug。
-->421六个。从(e,无)升起
422除(SocketTimeout、BaseSLerror、SocketError)外,如e:
raise\U from(值,from值)中的~\Anaconda3\lib\site packages\urllib3\packages\six.py
请求中的~\Anaconda3\lib\site packages\urllib3\connectionpool.py(self、conn、方法、url、超时、分块、**httplib\u请求)
415尝试:
-->416 httplib_response=conn.getresponse()
417基本例外情况除外,如e:
getresponse中的~\Anaconda3\lib\http\client.py(self)
1320尝试:
->1321响应。开始()
1322除连接错误外:
begin(self)中的~\Anaconda3\lib\http\client.py
295虽然正确:
-->296版本,状态,原因=self.\u读取\u状态()
297如果状态!=继续:
~\Anaconda3\lib\http\client.py处于读取状态(self)
256 def读取状态(自身):
-->257line=str(self.fp.readline(_MAXLINE+1),“iso-8859-1”)
258如果透镜(线)>最大线:
读入中的~\Anaconda3\lib\socket.py(self,b)
588试试:
-->589返回自我。接收到(b)
590除超时外:
将~\Anaconda3\lib\site packages\urllib3\contrib\pyopenssl.py放入(self,*args,**kwargs)
317其他:
-->318升高承插器ROR(str(e))
319除OpenSSL.SSL.ZeroReturnError外:
OSError:(10054,'WSAECONNRESET')
在处理上述异常期间,发生了另一个异常:
协议错误回溯(最后一次最近调用)
发送中的~\Anaconda3\lib\site packages\requests\adapters.py(self、request、stream、timeout、verify、cert、proxies)
448次重试=自最大重试次数,
-->449超时=超时
450                 )
urlopen中的~\Anaconda3\lib\site packages\urllib3\connectionpool.py(self、method、url、body、headers、retries、redirect、assert\u same\u host、timeout、pool\u timeout、release\u conn、chunked、body\u pos、**response\u kw)
719重试次数=重试次数。增量(
-->720方法,url,错误=e,_pool=self,_stacktrace=sys.exc_info()[2]
721             )
增量中的~\Anaconda3\lib\site packages\urllib3\util\retry.py(self、方法、url、响应、错误、\u pool、\u stacktrace)
399如果读取为False或非self.\u是\u方法\u可重试(方法):
-->400升起六个。重新升起(类型(错误),错误,_stacktrace)
401 elif read不是无:
重新播放中的~\Anaconda3\lib\site packages\urllib3\packages\six.py(tp,value,tb)
733如果值.\uuuu回溯\uuuuu不是tb:
-->734通过回溯(tb)提升值
735提高价值
urlopen中的~\Anaconda3\lib\site packages\urllib3\connectionpool.py(self、method、url、body、headers、retries、redirect、assert\u same\u host、timeout、pool\u timeout、release\u conn、chunked、body\u pos、**response\u kw)
671页眉=页眉,
-->672分块=分块,
673             )
请求中的~\Anaconda3\lib\site packages\urllib3\connectionpool.py(self、conn、方法、url、超时、分块、**httplib\u请求)
420#否则它看起来像是代码中的一个bug。
-->421六个。从(e,无)升起
422除(SocketTimeout、BaseSLerror、SocketError)外,如e:
raise\U from(值,from值)中的~\Anaconda3\lib\site packages\urllib3\packages\six.py
请求中的~\Anaconda3\lib\site packages\urllib3\connectionpool.py(self、conn、方法、url、超时、分块、**httplib\u请求)
415尝试:
-->416 httplib_response=conn.getresponse()
417基本例外情况除外,如e:
getresponse中的~\Anaconda3\lib\http\client.py(self)
1320尝试:
->1321响应。开始()
1322除连接错误外:
begin(self)中的~\Anaconda3\lib\http\client.py
295虽然正确:
-->296版本,状态,原因=self.\u读取\u状态()
297如果状态!=继续:
~\Anaconda3\lib\http\client.py处于读取状态(self)
256 def读取状态(自身):
-->257line=str(self.fp.readline(_MAXLINE+1),“iso-8859-1”)
258如果透镜(线)>最大线:
读入中的~\Anaconda3\lib\socket.py(self,b)
588试试:
-->589返回自我。接收到(b)
590除超时外:
将~\Anaconda3\lib\site packages\urllib3\contrib\pyopenssl.py放入(self,*args,**kwargs)
317其他:
-->318升高承插器ROR(str(e))
319除OpenSSL.SSL.ZeroReturnError外:
协议错误:('Connection aborted',OSError('10054','WSAECONNRESET'))
在处理上述异常期间,发生了另一个异常:
ConnectionError回溯(最近一次呼叫上次)
在里面
1 url=http://www.trading212.com/e
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15'}
response = requests.get(url, headers=headers)