擅长:python、mysql、java
<p>对我有效的方法是捕获未完成读取作为异常,并通过将其放入如下循环来获取您在每次迭代中设法读取的数据:(注意,我使用的是Python 3.4.1,urllib库在2.7和3.4之间发生了变化)</p>
<pre><code>try:
requestObj = urllib.request.urlopen(url, data)
responseJSON=""
while True:
try:
responseJSONpart = requestObj.read()
except http.client.IncompleteRead as icread:
responseJSON = responseJSON + icread.partial.decode('utf-8')
continue
else:
responseJSON = responseJSON + responseJSONpart.decode('utf-8')
break
return json.loads(responseJSON)
except Exception as RESTex:
print("Exception occurred making REST call: " + RESTex.__str__())
</code></pre>