当我使用请求包来检索超过大约185KB的响应时,我得到以下错误(仅显示尾部)。对同一URL的较短响应可以正常工作。这是Python 2.7,请求2.7.0,pyOpenSSL 0.15.1和urllib3 1.10.4。
In [42]: req = requests.post(url, headers, params=data)
/usr/lib/python2.7/httplib.pyc in _read_chunked(self, amt)
601 value.append(self._safe_read(chunk_left))
602 elif amt < chunk_left:
--> 603 value.append(self._safe_read(amt))
604 self.chunk_left = chunk_left - amt
605 return ''.join(value)
/usr/lib/python2.7/httplib.pyc in _safe_read(self, amt)
656 s = []
657 while amt > 0:
--> 658 chunk = self.fp.read(min(amt, MAXAMOUNT))
659 if not chunk:
660 raise IncompleteRead(''.join(s), amt)
/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.pyc in read(self, size)
144 # fragmentation issues on many platforms.
145 try:
--> 146 data = self._sock.recv(left)
147 except OpenSSL.SSL.WantReadError:
148 continue
SysCallError: (-1, 'Unexpected EOF')
网址为:https://secure.networkmerchants.com/api/query.php
如果我在请求包可用之前返回到我的方式,那么无论数据大小如何,查询也可以正常工作。那是使用urllib2。