Я пытаюсь создать функцию Python Amazon Lambda, которая использует Google Sheets API для редактирования листа. Я использую virtualenv и мой скрипт совместим с python3.6. Я убедился, что config.json
и token.json
доступны для чтения. Смотрите мой код ниже:
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import json
def lamda_handler(event, context):
store = file.Storage("token.json")
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets("credentials.json", 'https://www.googleapis.com/auth/spreadsheets') # If modifying these scopes, delete the file token.json.
creds = tools.run_flow(flow, store)
service = build('sheets', 'v4', http=creds.authorize(Http()))
# Call the Sheets API
SPREADSHEET_ID = 'Google_Sheet_ID'
RANGE_NAME = 'Sheet1!A1:A'
result = service.spreadsheets().values().get(spreadsheetId=SPREADSHEET_ID,
range=RANGE_NAME).execute()
value_range_body = {
"majorDimension": "ROWS",
"range": "Sheet1!A1:A",
"values": [
[
"lamda"
],
[
898449
]
]
}
request = service.spreadsheets().values().update(spreadsheetId=SPREADSHEET_ID,
range=RANGE_NAME, valueInputOption='RAW', body=value_range_body)
response = request.execute()
values = result.get('values', [])
if not values:
return {
"statusCode": 200,
"body": json.dumps('No data found.')
}
else:
return {
"statusCode": 200,
"body": json.dumps(values)
}
Я получаю следующую ошибку каждый раз, когда вызываю лямбда-функцию:
START RequestId: 43ca08ba-ad6b-11e8-b8e7-251d743c1903 Version: $LATEST
[WARNING] 2018-08-31T22:14:45.3Z 43ca08ba-ad6b-11e8-b8e7-251d743c1903 file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Traceback (most recent call last):
File "/var/task/googleapiclient/discovery_cache/__init__.py", line 36, in autodetect
from google.appengine.api import memcache
ModuleNotFoundError: No module named 'google.appengine'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/task/googleapiclient/discovery_cache/file_cache.py", line 33, in <module>
from oauth2client.contrib.locked_file import LockedFile
ModuleNotFoundError: No module named 'oauth2client.contrib.locked_file'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/task/googleapiclient/discovery_cache/file_cache.py", line 37, in <module>
from oauth2client.locked_file import LockedFile
ModuleNotFoundError: No module named 'oauth2client.locked_file'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/task/googleapiclient/discovery_cache/__init__.py", line 41, in autodetect
from . import file_cache
File "/var/task/googleapiclient/discovery_cache/file_cache.py", line 41, in <module>
'file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth')
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 or google-authEND RequestId: 43ca08ba-ad6b-11e8-b8e7-251d743c1903
REPORT RequestId: 43ca08ba-ad6b-11e8-b8e7-251d743c1903 Duration: 3003.24 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 44 MB
2018-08-31T22:14:47.989Z 43ca08ba-ad6b-11e8-b8e7-251d743c1903 Task timed out after 3.00 seconds
Есть идеи, что должно быть не так?