问题标签 [aiohttp]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - asyncio web 抓取 101:使用 aiohttp 获取多个 url
在较早的问题中,其中一位作者aiohttp
提出了使用 aiohttp 获取多个 url 的好方法,该方法使用来自以下的新async with
语法Python 3.5
:
但是,当其中一个session.get(url)
请求中断时(如上所述,因为http://SDFKHSKHGKLHSKLJHGSDFKSJH.com
),错误不会被处理并且整个事情都会中断。
我寻找插入有关结果的测试的方法session.get(url)
,例如寻找 atry ... except ...
或 a 的位置,if response.status != 200:
但我只是不了解如何使用async with
以及await
各种对象。
由于async with
还很新,所以例子不多。如果一个asyncio
向导可以展示如何做到这一点,这对许多人来说将是非常有帮助的。毕竟,大多数人想要测试的第一件事asyncio
就是同时获取多个资源。
目标
目标是我们可以检查the_results
并快速查看:
- 此 url 失败(以及原因:状态代码,可能是异常名称),或
- 这个网址有效,这是一个有用的响应对象
python - aiohttp.Timeout 和 asyncio.InvalidStateError
我正在使用 python 3.4.3 定期向多个 url 发送请求。这是我编写的协程(我省略了一些错误处理以简化代码):
我正在ping
使用asyncio.gather
. 但有时当服务器响应时间过长时,我会遇到InvalidStateError
异常:
该脚本继续工作,但我怎样才能使这个回溯保持沉默?这是一个错误还是我做错了什么?
我唯一的想法是,当 Web 服务器最终响应时,asyncio(或 aiohttp)会尝试将 restult 设置Future
为已经取消的那个。
编辑:
这是我启动该ping
协程的方式:
python-3.x - gunicorn with gaiohttp worker always returning 404 with flask app
I am running a flask app using gunicorn behind nginx proxy and am trying to get the gaiohttp worker to work. The app just returns 404 for all URLS when the gaiohttp worker is selected
When using the sync or gevent workers everything works fine. Also not running directly to gunicorn and gaiohttp i.e. not using nginx it works fine.
I have read everything I can find.
Am I missing something? Is gaiohttp worker valid when running behind a nginx proxy?
My nginx config:
gunicorn:
Using the latest versions of gunicorn etc etc.
python-asyncio - 检测客户端何时关闭来自 aiohttp 请求处理程序的连接
我有一个长时间运行的请求,在此期间我将收到的数据推送到客户端。但是,该请求需要一些在服务器端创建的资源,我想在客户端断开连接时清理这些资源。我查看了文档,但似乎找不到一种方法来检测何时发生这种情况。有任何想法吗?
python-3.5 - 将 web.Application 与多处理一起使用
我试图了解如何使这个例子成为一个aiohttp.web.Application
实例,以便它可以使用这种模式:
让我的生活变得困难的是,我已经能够将我的应用程序实例带到 ChildProcess。init但无法弄清楚如何修改启动方法(我只保留了需要帮助修改的部分):
python-3.x - 将 aiohttp 请求与其响应相关联
非常简单,我只想将来自aiohttp
异步 HTTP 请求的响应与标识符(例如字典键)相关联,以便我知道哪个响应对应于哪个请求。
例如,下面的函数调用以 dict values 和 为后缀1
的2
URI 3
。如何修改它以返回与每个结果关联的键?我只需要能够跟踪哪个请求是哪个......对于熟悉的人来说无疑是微不足道的asyncio
输出(缩写):
期望的输出(例如):
python - python anaconda - 管理不同python版本的模块
我的 Anaconda 中有 2 个版本的Python
mac(2.7 和 3.5.1)。当每一个我
它会自动进入/anaconda/lib/python2.7/site-packages
文件夹。现在我想学习aiohttp
,当我安装它时
它会给我错误:
raise RuntimeError("aiohttp 需要 Python 3.4.1+") RuntimeError: aiohttp 需要 Python 3.4.1+
/private/var/folders/c2/3yxfnvc51fng531jz312t00m0000gn/T/pip-build-m_mCpM/aiohttp/
- 我该如何解决这个问题?
Python
管理in的 2 个版本的最佳方法是Anaconda
什么?
python - 有没有办法将 aiohttp 客户端与 socks 代理一起使用?
看起来aiohttp.ProxyConnector
不支持 socks 代理。有什么解决方法吗?我将不胜感激任何建议。
python - Python3模块安装
我正在尝试为 python 安装模块 aiohttp,以便我可以设置一个系统来使用 uvloop 下载文件。但是,当我进入将 aiohttp 提取到的文件夹并执行以下命令时,我遇到了一些困难:
我环顾四周,发现有些人遇到了这个问题,但通过获取 python-setuptools 或 python3-setuptools 包解决了这个问题。所以我试着这样做,但这是我得到的输出:
这让我相信 python-setuptools 已经安装了!我不知道从这里去哪里。为了清楚起见,我确实尝试过
但我收到一个错误,因为安装 aiohttp 需要 Python 3.4.1+:
我在 HP Elitebook 8440p 上运行 Linux Mint 17.2 Qiana。关于我应该做什么的任何建议?提前致谢!