添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
首发于 一点鑫得

浏览器却可以正常访问的url,requests.get却返回Remote end closed connection without response错误

近期遇到一个问题使用python requests.get发送http请求,有些url直接报错,返回requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')),但是浏览器却可以正常打开网页,这是怎么回事呢?

报错信息详情如下:

r=requests.get("http://www.xxz.gov.cn/2018zhuanti/jczwgkzl/bmfl.html?Parent=14")
Traceback (most recent call last):
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1347, in getresponse
    response.begin()
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 276, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 440, in send
    resp = conn.urlopen(
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1347, in getresponse
    response.begin()
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 276, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\zhongxin\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 501, in send