下面的代码似乎发布了请求并重新发布和错误:
hashId = output["requestId"] # finds what the result id is
KeyError: 'requestId'
我不确定为什么不打印' JSON语法错误'并停在那里。
由于
import json
import requests
def read_json_file(file):
try:
return json.load(file)
except ValueError:
print('JSON syntax error')
def returnRequestId(working_file, url, username, password):
try:
with open(working_file, 'r') as fh:
data = read_json_file(fh)
requestpost = requests.post(url, json=data, auth=(username, password))
output = requestpost.json()
hashId = output["requestId"]
return hashId
except ValueError:
print('no request id')