什么可以导致python请求“IncompleteRead:IncompleteRead(0字节读取)”异常?

时间:2015-08-17 16:25:46

标签: python http python-3.x exception python-requests

我有一个我不能get()requests模块的网址,可能是由于响应编码错误。

这是伪:

import requests
r = requests.get(url) # exception

回溯:

> Traceback (most recent call last):
File "/usr/lib/python3.4/http/client.py", line 614, in _readinto_chunked
chunk_left = self._read_next_chunk_size()
File "/usr/lib/python3.4/http/client.py", line 559, in _read_next_chunk_size
return int(line, 16)
ValueError: invalid literal for int() with base 16: b''

During handling of the above exception, another exception occurred:

> Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/models.py", line 616, in generate
decode_content=True):
File "/usr/lib/python3/dist-packages/urllib3/response.py", line 225, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/lib/python3/dist-packages/urllib3/response.py", line 174, in read
data = self._fp.read(amt)
File "/usr/lib/python3.4/http/client.py", line 500, in read
return super(HTTPResponse, self).read(amt)
File "/usr/lib/python3.4/http/client.py", line 529, in readinto
return self._readinto_chunked(b)
File "/usr/lib/python3.4/http/client.py", line 618, in _readinto_chunked
raise IncompleteRead(bytes(b[0:total_bytes]))
http.client.IncompleteRead: IncompleteRead(0 bytes read)

During handling of the above exception, another exception occurred:

> Traceback (most recent call last):
File "test.py", line 8, in http_request_hook
return action(url, params = payload, cookies = cookies, headers = headers)
File "/usr/lib/python3/dist-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 455, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 558, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 394, in send
r.content
File "/usr/lib/python3/dist-packages/requests/models.py", line 679, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "/usr/lib/python3/dist-packages/requests/models.py", line 619, in generate
raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: IncompleteRead(0 bytes read)

HTTP 1.1

可能是什么原因?

UPD:过了一段时间,我再也没有链接,但我可以补充一点,这个链接来自网站,它有一些机器人的保护,我想挑战算法的作者。但最终以任何方式失败。

0 个答案:

没有答案