我有一个flask应用程序,如下所示: (注:为了这个问题,我简化了它)
@app.route("/app/ent/", methods=['POST'])
def methodpost():
req_data = request.get_json()
msg = req_data['msg']
output = jsonify(msg=msg)
return output
对于这个,我有一个蝗虫文件,看起来像这样:
from locust import HttpLocust, TaskSet, task, between
class MyClass(TaskSet):
@task(1)
def send_post(self):
self.client.headers['Content-Type'] = "application/json"
response = self.client.post("/app/ent/", json=
{
"msg": "test mesg example"
})
#temp
json_response_dict = response.json()
msg = json_response_dict['msg']
print("Post nessage returned is " + msg)
class MyTest(HttpLocust):
task_set = MyClass
wait_time = between(0.5, 3.0)
host = "http://localhost:5000"
我以如下方式开始蝗虫研究:
locust -f locust_myExample.py
然后,当我使用UI运行它时,会出现以下错误:
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
你知道如何打印烧瓶应用程序返回的“msg”吗
然而,为了确保它工作,当我使用cURL进行手动测试时,它返回“msg”
curl --header "Content-Type: application/json" \
--request POST \
--data '{"msg":"test mesg example"}' \
http://localhost:5000/app/ent
test mesg example
解决办法是:
返回的响应不是json,当它最终返回为json时,它可以工作。 该行丢失:
相关问题 更多 >
编程相关推荐