user_info = json.dumps({"bio":biography, "interests":interest_indexes})
headers = {'Content-type':'application/json'}
url = "http://0.0.0.0:5000/users/" + str(user_id)
r = requests.post("http://0.0.0.0:5000/users/1", data=user_info, headers=headers)
我已经启用了日志记录,这是在 Flask 中。如果我使用正确的 JSON 响应正文手动对 URL 执行 POST 请求,它工作正常。它只是说 INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): 0.0.0.0
它就永远卡在那里。
有什么想法吗?
最佳答案
您需要在启用线程的情况下运行您的 Flask 应用。
app.run(threaded=True)
这当然不建议用于生产,只是为了快速开发:)
关于Python Requests Post 卡在开始新的 HTTP 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24254442/