2017-01-08 124 views
0

我在論壇上看到了這個錯誤,並通讀了答案,但我仍然不明白它是什麼或如何解決它。我從互聯網上從16k鏈接中獲取數據,我的腳本從每個鏈接中獲取類似的信息,並將其寫入一個.csv,在出現此錯誤之前會寫入一些日期。Python http.client.Incomplete Read(0字節讀取)錯誤

Traceback (most recent call last): 
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 541, in _get_chunk_left 
    chunk_left = self._read_next_chunk_size() 
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 508, 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/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 558, in _readall_chunked 
    chunk_left = self._get_chunk_left() 
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 543, in _get_chunk_left 
    raise IncompleteRead(b'') 
http.client.IncompleteRead: IncompleteRead(0 bytes read) 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
File "MoviesToDb.py", line 91, in <module> 
html = r.read() 
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 455, in read 
    return self._readall_chunked() 
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 565, in _readall_chunked 
    raise IncompleteRead(b''.join(value)) 
http.client.IncompleteRead: IncompleteRead(17891 bytes read) 

我想知道:
1)這個錯誤是什麼意思?
2)我如何防止它?

回答

-1

嘗試導入:

from http.client import IncompleteRead 

,並在腳本中添加此:

except IncompleteRead: 
    # Oh well, reconnect and keep trucking 
     continue 
+0

他不值得-2。他的解決方案確實奏效 –