【问题标题】:Python async webservice callPython 异步 Web 服务调用
【发布时间】:2014-04-25 07:06:39
【问题描述】:

我有一个覆盆子模块,其中运行 python 代码。现在我必须从中异步调用 Web 服务。但是当我编写代码并执行时会出现类似

的错误
    Traceback (most recent call last):
  File "async_ws.py", line 3, in <module>
    from requests import async
ImportError: cannot import name async

我的代码是这样的

import json
import requests
from requests import async

urls = [
    'http://python-requests.org',
    'http://httpbin.org',
    'http://python-guide.org',
    'http://kennethreitz.com'
]

rs = [async.get(u) for u in urls]
async.map(rs)

请帮帮我

【问题讨论】:

标签: python web-services asynchronous web raspberry-pi


【解决方案1】:

这看起来不像是用于 python 请求的最常见的异步库,它们是 grequests(使用 gevent)和 requests-futures。我想看看你是否可以从https://github.com/ross/requests-futures 安装 requests-futures(包括从 python 3 反向移植的 concurrent.futures,如果你正在运行 python 2)。

【讨论】:

猜你喜欢
  • 2023-03-15
  • 2011-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-03
相关资源
最近更新 更多