python - Google Drive API 快速入门 UnicodeDecodeError:
问题描述
我尝试按照谷歌驱动api教程的介绍:developers.google.com/drive/api/v3/quickstart/python,但是下面运行示例文件quickstart.py时卡住了:
from __future__ import print_function
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
def main():
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('drive', 'v3', http=creds.authorize(Http()))
results = service.files().list(
pageSize=10, fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print(u'{0} ({1})'.format(item['name'], item['id']))
if __name__ == '__main__':
main()
我得到如下错误:
C:\Users\mhlai.TARI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauth2client\_helpers.py:255: UserWarning: Cannot access token.json: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Traceback (most recent call last):
File "quickstart.py", line 48, in <module>
main()
File "quickstart.py", line 32, in main
creds = tools.run_flow(flow, store)
File "C:\Users\mhlai.TARI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauth2client\_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\mhlai.TARI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauth2client\tools.py", line 203, in run_flow
ClientRedirectHandler)
File "C:\Users\mhlai.TARI\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 449, in __init__
self.server_bind()
File "C:\Users\mhlai.TARI\AppData\Local\Programs\Python\Python37-32\lib\http\server.py", line 139, in server_bind
self.server_name = socket.getfqdn(host)
File "C:\Users\mhlai.TARI\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 0: invalid start byte
问题一:介绍中找不到token.json,不知道有没有必要。
问题 2:我可以为错误信息做什么?
任何答案都有帮助,非常感谢。
我的开发环境是python3.7
解决方案
推荐阅读
- bbedit - 如何为文档设置语法着色?
- c# - 具有相同类型的多对多和一对多关系
- c# - 如何使用 C# 检查单元 (C:) 脏位
- c - Linux消息发送方和接收方执行错误(重复错误)
- javascript - 使用 chai-http 测试的测试没有运行
- javascript - 在'beforeunload'函数之前反应状态变量神秘地变化
- javascript - 这是什么错误?尝试使用带有回调的 API
- dictionary - Flutter - 如何在我的未来构建器文本小部件中获得价值回报
- swift - 将文本从 UITextView 保存到领域(Swift 5)时出现问题
- mysql - 有效的数据库使用