我目前正在调查pulsar
的异步HTTP客户端。Python 3.5异步关键字
下面的例子是在文档:
from pulsar.apps import http
async with http.HttpClient() as session:
response1 = await session.get('https://github.com/timeline.json')
response2 = await session.get('https://api.github.com/emojis.json')
但是当我试着执行它时,我得到
async with http.HttpClient() as session:
^SyntaxError: invalid syntax
它看起来像async
关键字无法识别。我正在使用Python 3.5。
工作例如:
import asyncio
from pulsar.apps.http import HttpClient
async def my_fun():
async with HttpClient() as session:
response1 = await session.get('https://github.com/timeline.json')
response2 = await session.get('https://api.github.com/emojis.json')
print(response1)
print(response2)
loop = asyncio.get_event_loop()
loop.run_until_complete(my_fun())
你绝对_certain_你使用Python 3.5? – byxor
$ python3 Python 3.5.2(默认,2016年11月17日,17:05:23) – Markus
尝试'从pulsar.apps.http导入HttpClient'和'使用HttpClient()异步'来查看错误是否更改。 – byxor