我试图使用Python google-cloud-tasks==2.1.0使用Google任务创建一个任务,但我得到了一个例外,即HttpRequest.url是必需的。我正在设置相对url,这是一个在我的应用程序中处理任务的URL。
队列存在并已使用以下方法创建:
gcloud task create queue notifications守则:
client = tasks_v2.CloudTasksClient()
parent = client.queue_path(project, location, queue)
task = {
'app_engine_http_request': {
'http_method': tasks_v2.HttpMethod.POST,
'relative_uri': notification_url,
'body': payload.encode('utf-8')
},
'http_request': {
'headers': {"Content-type": "application/json"}
}
}
response = client.create_task(parent=parent, task=task) 我收到的确切错误是:
google.api_core.exceptions.InvalidArgument: 400 HttpRequest.url is required我正试图在我的App标准环境中创建任务。
发布于 2021-01-26 17:23:20
@Donald是对的,但我认为他链接的google文档中有一个错误。我在app_engine_http_request中设置了头,而不是http_request。
我认为你不能同时提供app_engine_http_request和http_request,你只能提供一个。就像这样:
client = tasks_v2.CloudTasksClient()
parent = client.queue_path(project, location, queue)
task = {
'app_engine_http_request': {
'http_method': tasks_v2.HttpMethod.POST,
'relative_uri': notification_url,
'headers': {
'Content-Type': 'application/json'
},
'body': payload.encode('utf-8')
}
}
response = client.create_task(parent=parent, task=task)https://stackoverflow.com/questions/65891363
复制相似问题