【发布时间】:2017-12-18 10:54:34
【问题描述】:
在我的项目中,我开发了一个 python 脚本来检查并在我的谷歌日历上自动创建一个约会。 首先我从谷歌开发控制台 OAUTH json 文件创建,然后验证并运行我的脚本:
SCOPES = 'https://www.googleapis.com/auth/calendar'
CLIENT_SECRET_FILE = 'client_id.json'
APPLICATION_NAME = 'Google Calendar API Python Quickstart'
def get_credentials():
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,
'calendar-python-quickstart.json')
store = 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
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('calendar', 'v3', http=http)
当我从本地机器运行它时,一切都完成了,但是当我使用 AWS lambda 函数上传脚本和所有依赖项时,当我测试它时,服务器响应:
{ "errorMessage": "模块初始化错误" }
START RequestId:2244eefe-e3dd-11e7-a0ce-93ed40a4fa13 版本:$LATEST 模块初始化错误:[Errno 30] 只读文件系统:'/home/sbx_user1060'
我认为这是因为身份验证方法在本地计算机上存储和检索 json 凭据文件,但是我如何从服务器服务器而不是客户端服务器进行身份验证和运行代码?
提前致谢
【问题讨论】:
标签: python json oauth aws-lambda google-api-python-client