我正试图为Google创建事件,但我正在为‘client_Incre.json’获得一个FileNotFoundError。
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store, flags) \
if flags else tools.run(flow, store)
CAL = build('calendar', 'v3', http=creds.authorize(Http()))
GMT_OFF = '-07:00' # PDT/MST/GMT-7
EVENT = {
'summary': 'Dinner with friends',
'start': {'dateTime': '2015-09-15T19:00:00%s' % GMT_OFF},
'end': {'dateTime': '2015-09-15T22:00:00%s' % GMT_OFF},
'attendees': [
{'email': 'friend1@example.com'},
{'email': 'friend2@example.com'},
],
}
e = CAL.events().insert(calendarId='primary',
sendNotifications=True, body=EVENT).execute()
print('''*** %r event added:
Start: %s
End: %s''' % (e['summary'].encode('utf-8'),
e['start']['dateTime'], e['end']['dateTime']))以下是错误:
警告(来自警告模块):文件"C:\Users\bakat\AppData\Local\Programs\Python\Python35-32\lib\site-packages\oauth2client_helpers.py",行255 warnings.warn(_MISSING_FILE_MESSAGE.format(filename)) UserWarning:无法访问storage.json:没有这样的文件或目录跟踪(最近一次调用):"C:\Users\bakat\AppData\Local\Programs\Python\Python35-32\lib\site-packages\oauth2client\clientsecrets.py",第121行,在打开(文件名,'r')为fp: FileNotFoundError: Errno 2的_loadfile中,没有这样的文件或目录:'client_secret.json‘ 在处理上述异常的过程中,发生了另一个异常: 回溯(最近一次调用):文件"C:/Users/bakat/AppData/Local/Programs/Python/Python35-32/Diet Buddy/Google_ client.flow_from_clientsecrets('client_secret.json',. in“,第16行,在flow =client.flow_from_clientsecrets(‘client_secret.json’,作用域)文件"C:\Users\bakat\AppData\Local\Programs\Python\Python35-32\lib\site-packages\oauth2client_helpers.py",第133行,在positional_wrapper返回包装(*args,**kwargs)文件"C:\Users\bakat\AppData\Local\Programs\Python\Python35-32\lib\site-packages\oauth2client\client.py",第2125行,在flow_from_clientsecrets cache=cache中)文件"C:\Users\bakat\AppData\Local\Programs\Python\Python35-32\lib\site-packages\oauth2client\clientsecrets.py",第165行在加载文件中,返回"C:\Users\bakat\AppData\Local\Programs\Python\Python35-32\lib\site-packages\oauth2client\clientsecrets.py",文件的_loadfile (文件名)第125行,在_loadfile exc.strerror,exc.errno中) oauth2client.clientsecrets.InvalidClientSecretsError:(“错误打开文件”,“client_Incre.json”,“没有这样的文件或目录”,2)
发布于 2017-04-05 02:06:12
我发现了这个问题--您必须去https://developers.google.com/gmail/api/quickstart/python并按照说明下载您的client_secrets.json。
https://stackoverflow.com/questions/43220123
复制相似问题