【问题标题】:Does python-requests support HTTP2 and asynchronous calls?python-requests 是否支持 HTTP2 和异步调用?
【发布时间】:2017-12-09 09:47:45
【问题描述】:

我想在我的服务器中使用 python-requests 向 Apple 推送服务器发送 PUSH 通知,我的问题:

  1. python-requests 是否支持异步调用?
  2. python-request 支持 HTTP2 吗?

谢谢

【问题讨论】:

  • 不,它没有。

标签: asynchronous python-requests http2


【解决方案1】:

作为recommended by @qris in this comment,你应该考虑使用HTTPX (https://github.com/encode/httpx/)。

它处于测试阶段,但计划在 2021 年发布 1.0 版本。

它同时支持异步和 HTTP/2,并提供与请求兼容的 API。

【讨论】:

    【解决方案2】:

    它现在不支持 HTTP/2(发布 v2.18.1)。 如文档 (http://docs.python-requests.org/en/master/) 中所述:

    Requests 允许您发送自然的、草稿式 HTTP/1.1 请求,而无需人工操作。

    但如果您需要发送 HTTP/2 请求,您可以尝试Hyper: https://hyper.readthedocs.io/en/latest/.

    hyper 支持 Python 3.4 和 Python 2.7.9,可以说 HTTP/2 和 HTTP/1.1。

    【讨论】:

    • 鉴于 Hyper 是 alpha 软件并且 4 年内没有发布过,您最好使用 HTTPX。它处于测试阶段,并计划很快(2020 年 4 月)发布稳定版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-07
    • 2018-07-13
    • 1970-01-01
    • 2013-09-25
    • 2020-09-04
    • 2017-07-27
    相关资源
    最近更新 更多