Python Requests Post 卡在开始新的 HTTP 连接

标签 python json flask python-requests

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/

相关文章:

python - 在我的表单中使用MultipleFileField()时,FileRequiredValidator()不起作用

python while 和 if 与条件对

python - 无法根据规则 ('O' 将数组数据从 dtype ('float64' ) 转换为 dtype 'safe' )

jquery - 从本地文件加载时数据表抛出 "invalid JSON"错误

javascript - 获取属性的值 - javascript

python - 使用nginx/flup重新请求后,如何运行后台线程?

python - Flask-Python 空 html 输入返回值的特征

python - Cython 将字符串作为字节传递给 C

python - 如何在 Python 中暂停多处理进程?

javascript - 使用 AJAX 将 JSON 转换为 PHP