我正在尝试编写一个为Elastic Search创建请求对象的函数。这是我的代码,
URL = 'http:localhost:4443/'
def get_request_object(row):
headers = {'Content-Type': 'application/json'}
data = [{"update": "id:prism:prismaggregation:g={}:{}".format(row.ownerid, row.mediaid), "create": true,
"fields": {"mediaid": {"assign": {"".format(row.mediaid)},
"ownerid": {"assign": {"".format(row.ownerid)}},
"storyid": {"assign": {"".format(row.storyid)}}}}]
#data.append(payload)
response = requests.post(URL, data=data, timeout=5)
return response
我相当确定这个代码块在语法上是正确的。但是,当我在jupyter笔记本上运行它时,我收到以下错误,
File "<ipython-input-12-630242a1363f>", line 7
"storyid": {"assign": {"".format(row.story_id)}}}}]
^
SyntaxError: invalid syntax
我在这里缺少什么?
答案 0 :(得分:2)
你需要一个额外的}第5行(这里的第二行):
data = [{"update": "id:prism:prismaggregation:g={}:{}".format(row.ownerid, row.mediaid), "create": true,
"fields": {"mediaid": {"assign": {"".format(row.mediaid)}},
"ownerid": {"assign": {"".format(row.ownerid)}},
"storyid": {"assign": {"".format(row.storyid)}}}}]