【问题标题】:Does the aiohttp Python library in Windows support HTTPS?Windows 中的 aiohttp Python 库是否支持 HTTPS?
【发布时间】:2014-04-21 18:54:40
【问题描述】:

当我在 Windows 7 中使用带有 asyncio 和 Python 3.4 的 aiohttp 库发出 HTTPS 请求时,请求失败并在 base_events.py 中的 _make_ssl_transport 函数中出现 NotImplementedError,如回溯中所示。

在 Windows 上,我使用 ProactorEventLoop。我认为你必须使用那个来让 asyncio 工作。我在带有 Python 3.4 编译版本的 Debian 7 VM 中尝试了相同的请求,并且相同的请求有效。我不使用 Debian 中的 ProactorEventLoop,只是默认的。

有什么想法或解决方法吗?或者,我现在应该放弃 Windows 上的 aiohttp HTTPS 吗?我无法在这个项目中使用 Linux,需要在 Windows 上。

【问题讨论】:

  • 你需要ProactorEventLoop()read output from subprocesses' pipes using asyncio。尝试使用默认循环(删除 set_event_loop() 调用)来发出 https 请求。
  • 这似乎行得通,但唯一的问题是,当我关闭循环时,我总是会得到一个异常,即使没有更多的待处理任务。
  • 这只是意味着您的代码中存在多个问题。创建minimal complete code examplepost it as a question
  • @J.F.Sebastian - 您之前关于使用默认事件循环的评论适用于 Windows 上的 HTTPS,谢谢。 ProactorEventLoop 似乎不起作用。如果在 Windows 上的 Python 中运行 shell 命令和 HTTP(S) 请求,我想我需要 2 个循环。
  • 你可以post your comment as an answer and accept it: 1. ProactorEventLoop 与 SSL 不兼容 2. 默认循环在 Windows 上支持 SSL,通过扩展 aiohttp 也应该在 Windows 上与 https 一起使用。

标签: python windows python-3.x python-asyncio


【解决方案1】:

正如 jfs 和 OP 所观察到的,

  1. ProactorEventLoop 与 SSL 不兼容,并且
  2. 默认循环支持 Windows 上的 SSL。通过扩展 aiohttp 也应该在 Windows 上与 https 一起使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 2015-02-09
    • 2018-12-26
    • 1970-01-01
    • 2012-10-11
    • 2023-03-30
    • 2018-02-15
    相关资源
    最近更新 更多