Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python httplib2.UncompleteRead:AttributeError:“模块”对象没有属性“UncompleteRead”_Python_Google Drive Api_Httplib2 - Fatal编程技术网

Python httplib2.UncompleteRead:AttributeError:“模块”对象没有属性“UncompleteRead”

Python httplib2.UncompleteRead:AttributeError:“模块”对象没有属性“UncompleteRead”,python,google-drive-api,httplib2,Python,Google Drive Api,Httplib2,我一直在使用一个不再维护的脚本,它将把你的整个谷歌硬盘下载到你的本地存储中。我设法解决了一些与折旧有关的问题,脚本似乎运行得很顺利,但是,由于脚本中出现了随机时间,它将中断,我将收到以下错误 File "drive.py", line 169, in download_file except httplib2.IncompleteRead: AttributeError: 'module' object has no attribute '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模块不一样

可以找到完整的代码


提前感谢所有能够为可能的修复提供帮助的人。

我一直在更新驱动器备份脚本,但遇到了相同的错误。我还没有弄清楚抛出了什么异常,但为了揭示它是什么并允许脚本继续运行,我做了以下更改:

删除此项:

-        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:

此更改在存储库中可见

如果我再次遇到此错误,我将更新此答案,并提供更多详细信息。

您可能需要检查此问题,其中提到了在读取链接时加入try/catch循环,或者只需在代码中发送HTTP/1.0请求。可能也有帮助。