python API启动模板未知名称找不到字段 [英] python api to launch template unknown name cannot find field
问题描述
我创建并运行了DataPrep作业,并尝试在应用程序引擎上使用python中的模板. 我可以使用
I've created and run a DataPrep job, and am trying to use the template from python on app engine. I can successfully start a job using
gcloud dataflow jobs run
--parameters "inputLocations={\"location1\":\"gs://bucket/folder/*\"},
outputLocations={\"location1\":\"project:dataset.table\"},
customGcsTempLocation=gs://bucket/DataPrep-beta/temp"
--gcs-location gs://bucket/DataPrep-beta/temp/cloud-dataprep-templatename_template
但是尝试在应用引擎上使用python;
however trying to use python on app engine;
service = build('dataflow', 'v1b3', credentials=credentials)
input1 = {"location1": "{i1}".format(i1=input)}
output1 = {"location1": "{o1}".format(o1=output)}
print('input location: {}'.format(input1))
GCSPATH="gs://{bucket}/{template}".format(bucket=BUCKET, template=template)
BODY = {
"jobName": "{jobname}".format(jobname=JOBNAME),
"parameters": {
"inputLocations": input1,
"outputLocations": output1,
"customGcsTempLocation": "gs://{}/DataPrep-beta/temp".format(BUCKET)
}
}
print("dataflow request body: {}".format(BODY))
request = service.projects().templates().launch(projectId=PROJECT, gcsPath=GCSPATH, body=BODY)
response = request.execute()
我回来;
"Invalid JSON payload received. Unknown name "location1" at
'launch_parameters.parameters[1].value': Cannot find field.
Invalid JSON payload received. Unknown name "location1" at
'launch_parameters.parameters[2].value': Cannot find field."
我尝试过的任何方法似乎都不支持将dict或json.dumps()或str()传递到"inputLocations"或"outputLocations".
Nothing I've tried seems to support passing a dict or a json.dumps() or a str() to "inputLocations" or "outputLocations".
推荐答案
问题与传递input1
和output1
的格式有关.
它们必须位于引号之间,如下所示:
The issue is with the format that you are passing input1
and output1
.
They need to be between quotation marks like this:
input1 = '{"location1":"' + input + '" }'
output1 = '{"location1":"' + output + '" }'
我尝试用与您相同的方法发送请求,但失败.如果我稍后将其解析回字符串或json,也会失败,因为它无法正确解析引号.
I have tried sending the request with the same approach than you and it fails. It also fails if I later parse it back to string or json because it doesn't parse quotes correctly.
这篇关于python API启动模板未知名称找不到字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!