Я получаю ошибку типа при попытке запустить следующий код в качестве облачной функции Google.
Это измененная версия: https://github.com/OWOX/BigQuery-integrations/tree/master/intercom
Где я жестко закодировалПараметры публикации и запуск функции в качестве подпрограммы / pub в облаке Google.
Я изменил внутреннюю связь основной функции, чтобы не принимать запрос публикации, который был исходным триггером для функции (см. выше github)и вместо этого жестко закодировали параметры, которые в противном случае были в посте.
payload = {
"intercom": {
"accessToken": "accesstoken",
"entities": [
"users",
"companies",
"contacts",
"admins",
"conversations",
"teams",
"tags",
"segments"
]
},
"bq": {
"project_id": "project_id",
"dataset_id": "dataset_id",
"location": "US"
}
}
def intercom():
try:
# get POST data from Flask.request object
intercom_configuration = payload["intercom"]
bq_configuration = payload["bq"]
if not bq_configuration.get("location"):
bq_configuration["location"] = "US"
except Exception as error:
print("An error occured with POST request data.")
print(str(error))
raise SystemExit
# go to writable directory
os.chdir(gc_write_dir)
# getting data from intercom
for entity in intercom_configuration["entities"]:
if entity in ("companies", "users"):
try:
json_file = get_intercom_data_scroll(intercom_configuration, entity)
# upload the file to BigQuery
try:
load_to_gbq(json_file, bq_configuration, entity)
except Exception as error:
print("An error occured trying to upload file to Google BigQuery.")
print(str(error))
except Exception as error:
print("An error occured trying to get data from intercom.")
print(str(error))
else:
try:
json_file = get_intercom_data(intercom_configuration, entity)
# upload the file to BigQuery
try:
load_to_gbq(json_file, bq_configuration, entity)
except Exception as error:
print("An error occured trying to upload file to Google BigQuery.")
print(str(error))
except Exception as error:
print("An error occured trying to get data from intercom.")
print(str(error))
print("All tasks have been completed.")
В коде есть намного больше, но в конечном итоге он должен получить данные из Интерком API и отправить их в большой запрос Google.
traceback:
"Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 383, in run_background_function
_function_handler.invoke_user_function(event_object)
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function
return call_user_function(request_or_event)
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 214, in call_user_function
event_context.Context(**request_or_event.context))
TypeError: intercom() takes 0 positional argument but 2 were given
}