httplib2.IncompleteRead: AttributeError: 'module' object has no attribute 'IncompleteRead'
httplib2.IncompleteRead: AttributeError: 'module' object has no attribute 'IncompleteRead'
我一直在使用一个不再维护的脚本,它将您的整个 Google 驱动器下载到您的本地存储。我设法解决了一些与折旧有关的问题,脚本似乎 运行 顺利,但是,由于我的脚本中看似随机的时间,它会崩溃,我会收到以下错误。
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
提前感谢任何可以解决可能问题的人。
我一直在更新那个驱动器备份脚本,但遇到了同样的错误。我还没有弄清楚抛出的异常是什么,但为了揭示它是什么(并允许脚本保持 运行),我做了以下更改:
删除这个:
- except httplib2.IncompleteRead:
- log( 'Error while reading file %s. Retrying...' % drive_file['title'].replace( '/', '_' ) )
替换为:
+ except Exception as e: #httplib2.IncompleteRead: # no longer exists
+ log( traceback.format_exc(e) + ' Error while reading file %s. Retrying...' % drive_file['title'].replace( '/', '_' ) )
这样也有缺点,如果一直遇到异常,可能会进入死循环。但是,它随后会显示实际抛出的异常,因此 "except:" 可以适当更新。
此更改在存储库中可见
here.
如果我再次遇到该错误,我会更详细地更新此答案。
我一直在使用一个不再维护的脚本,它将您的整个 Google 驱动器下载到您的本地存储。我设法解决了一些与折旧有关的问题,脚本似乎 运行 顺利,但是,由于我的脚本中看似随机的时间,它会崩溃,我会收到以下错误。
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
提前感谢任何可以解决可能问题的人。
我一直在更新那个驱动器备份脚本,但遇到了同样的错误。我还没有弄清楚抛出的异常是什么,但为了揭示它是什么(并允许脚本保持 运行),我做了以下更改:
删除这个:
- except httplib2.IncompleteRead:
- log( 'Error while reading file %s. Retrying...' % drive_file['title'].replace( '/', '_' ) )
替换为:
+ except Exception as e: #httplib2.IncompleteRead: # no longer exists
+ log( traceback.format_exc(e) + ' Error while reading file %s. Retrying...' % drive_file['title'].replace( '/', '_' ) )
这样也有缺点,如果一直遇到异常,可能会进入死循环。但是,它随后会显示实际抛出的异常,因此 "except:" 可以适当更新。
此更改在存储库中可见 here.
如果我再次遇到该错误,我会更详细地更新此答案。