【问题标题】:Python Requests Post is Stuck at Starting New HTTP ConnectionPython Requests Post 卡在启动新的 HTTP 连接时
【发布时间】:2014-08-06 21:54:22
【问题描述】:
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

它永远挂在那里。

有什么想法吗?

【问题讨论】:

  • IP 地址0.0.0.0 用于表示无效IP。也许这就是它挂起的原因?您是否尝试访问本地主机?如果是这样,请改用127.0.0.1localhost
  • 我刚试过127.0.0.1,它也挂了。与本地主机相同。
  • 处理端口 5000 的服务是什么?检查该服务是否有任何错误输出。
  • 对不起,我如何检查什么服务正在处理端口 5000?
  • 请同时粘贴服务器端脚本。

标签: python json flask python-requests


【解决方案1】:

您需要在启用线程的情况下运行烧瓶应用程序。

app.run(threaded=True)

这当然不建议用于生产,只是为了快速开发:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多