Python 异步网络服务调用

标签 python web-services asynchronous web raspberry-pi

我有一个运行 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 请求最常见的异步库,它们是 grequests(使用 gevent)和 requests-futures。我会看看你是否可以从 https://github.com/ross/requests-futures 安装请求 future (如果您运行的是 python 2,则包括从 python 3 向后移植的 concurrent.futures)。

关于Python 异步网络服务调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22499057/

相关文章:

node.js - Express JS - 检测计算机机器人、垃圾邮件

node.js - 使用 forEach 时避免回调多次调用

java - Spring Boot - @Async 被忽略

python - 如何对 python 图像(使用 numpy、opencv 或 PIL)的每个 PIXEL(不是每个 rgb 组件!)应用操作?

python - 如何使用 ElementTree 从深度嵌套的 XML 子元素中提取属性?

python - Pandas:如何通过保留第一个数据帧的信息来合并列上的两个数据帧?

events - 在 F# 中同时等待多个事件中的任何一个事件

python - 将键的字典和键内的字典列表保存到 JSON,其中字典按行存储

mysql - Azure应用服务:如何允许其余api访问mysql服务器?

javascript - 如何在WebMethod中接收非原始数据?