Я использую скрипт, который больше не поддерживается, который загружает весь Google Drive в локальное хранилище. Я сумел исправить несколько проблем, связанных с обесцениванием, и сценарий, казалось, работал гладко, однако, как казалось бы случайные времена в моем скрипте, он сломается, и я получу следующую ошибку.httplib2.IncompleteRead: AttributeError: объект 'module' не имеет атрибута 'IncompleteRead'
File "drive.py", line 169, in download_file
except httplib2.IncompleteRead:
AttributeError: 'module' object has no attribute 'IncompleteRead'
Эти модули я использую
import gflags, httplib2, logging, os, pprint, sys, re, time
import pprint
from apiclient.discovery import build
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError, flow_from_clientsecrets
from oauth2client.tools import run_flow
А вот код, который вызывает ошибку
if is_google_doc(drive_file):
try:
download_url = drive_file['exportLinks']['application/pdf']
except KeyError:
download_url = None
else:
download_url = drive_file['downloadUrl']
if download_url:
try:
resp, content = service._http.request(download_url)
except httplib2.IncompleteRead:
log('Error while reading file %s. Retrying...' % drive_file['title'].replace('/', '_'))
print 'Error while reading file %s. Retrying...' % drive_file['title'].replace('/', '_')
download_file(service, drive_file, dest_path)
return False
if resp.status == 200:
try:
target = open(file_location, 'w+')
except:
log("Could not open file %s for writing. Please check permissions." % file_location)
print "Could not open file %s for writing. Please check permissions." % file_location
return False
target.write(content)
return True
else:
log('An error occurred: %s' % resp)
print 'An error occurred: %s' % resp
return False
else:
# The file doesn't have any content stored on Drive.
return False
Я предполагаю, что эта ошибка имеет что-то делать с потерей соединения при загрузке, и я не знаком с модулем httplib2.
Полный код можно найти here
Thankyou заранее всем, кто может пролить некоторый свет на возможное исправление.
Возможно, вы захотите проверить это сообщение [SO post] (http://stackoverflow.com/questions/14442222/how-to-handle-incompleteread-in-python), в котором упоминалось о метании в цикле try/catch, где вы читаете ваши ссылки или просто отправляете HTTP/1.0 запрос в свой код. [IncompleteRead using httplib] (http://stackoverflow.com/questions/14149100/incompleteread-using-httplib) также может помочь. – Teyam