gpt4 book ai didi

Python Google Drive API discovery.build 失败,退出代码为 -1073740777 (0xC0000417)

转载 作者:行者123 更新时间:2023-12-01 04:20:50 25 4
gpt4 key购买 nike

我正在构建一个Python应用程序,它将图像上传到谷歌驱动器。然而,工作一段时间后,我的谷歌驱动器上传突然停止工作。每当我尝试初始化服务时,程序都会退出并显示代码 -1073740777 (0xC0000417)。

我已经尝试使用开发者控制台(也使用完全不同的 Google 帐户)创建新的 client_secret.json 文件并删除drive-python-quickstart.json 凭据文件。

我的 friend 使用相同的代码没有这个问题,正如我所说,这也对我有用了一段时间,但突然停止工作。

我正在运行 Windows 10 Pro x64 和 Python 3.5 32 位。

运行此示例程序时出现问题(取自 the Google quickstart guide ):

from __future__ import print_function
import httplib2
import os

from apiclient import discovery
import oauth2client
from oauth2client import client
from oauth2client import tools

try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None

SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Drive API Python Quickstart'


def get_credentials():
"""Gets valid user credentials from storage.

If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.

Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'drive-python-quickstart.json')

store = oauth2client.file.Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatibility with Python 2.6
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials

def main():
"""Shows basic usage of the Google Drive API.

Creates a Google Drive API service object and outputs the names and IDs
for up to 10 files.
"""
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('drive', 'v2', http=http)

results = service.files().list(maxResults=10).execute()
items = results.get('items', [])
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print('{0} ({1})'.format(item['title'], item['id']))

if __name__ == '__main__':
main()

最佳答案

在使用 Google Youtube API 时遇到同样的问题,也有相同的操作系统 (Win 10 Pro x64) 并使用相同的版本 oh python (3.5)。

我不知道怎么做,但在主函数中添加这一行有帮助

sys.modules['win32file'] = None

关于Python Google Drive API discovery.build 失败,退出代码为 -1073740777 (0xC0000417),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33724740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com