我目前正在寻找pulsar
一个异步 HTTP 客户端。
以下示例在文档中:
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())