Google Drive API QuickStart UnicodeDecodeError: - PullRequest
0 голосов
/ 12 октября 2018

Я пытался следовать введению учебника API диска Google: 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

Вопрос 1: Я не могу найти token.json во введении, и я не знал, нужно ли это или нет.

Вопрос 2. Что я могу сделать для получения информации об ошибке?

Любой ответ полезен, большое спасибо.

Моя среда разработки находится в python3.7

...