from google.cloud import tasks_v2
import json
GCP_PROJECT='test'
GCP_LOCATION='europe-west6'
def enqueue_task(queue_name, payload, process_url):
client = tasks_v2.CloudTasksClient()
parent = client.queue_path(GCP_PROJECT, GCP_LOCATION, queue_name)
task = {
'app_engine_http_request': {
'http_method': 'POST',
'relative_uri': process_url
}
}
if payload is None:
return False
payload = json.dumps(payload)
converted_payload = payload.encode()
task['app_engine_http_request']['body'] = converted_payload
return client.create_task(parent, task)
Run Code Online (Sandbox Code Playgroud)
当我尝试创建 Google Cloud 任务时,我不断收到以下错误。使用的 Google App Engine 运行时是 python38。它工作正常,但在使用 gcp CLI 部署后突然无法正常工作。
Traceback (most recent call last):
File "/layers/google.python.pip/pip/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/layers/google.python.pip/pip/flask/app.py", line 1952, in …Run Code Online (Sandbox Code Playgroud) python queue python-3.x google-cloud-platform google-cloud-tasks