1. 程式人生 > >python3 出現 IncompleteRead錯誤

python3 出現 IncompleteRead錯誤

python3 用urllib時,出現http.client.IncompleteRead: IncompleteRead(34144 bytes read) 錯誤程式碼:

原出錯程式碼:

html = urllib.request.urlopen(request).read().decode('utf-8')

 

解決方法:

try:
	html = urllib.request.urlopen(request).read().decode('utf-8')
except Exception as e:
	page = e.partial
	html = page.decode('utf-8')

即 捕獲異常, e.partial.decode('utf-8') 即可解決