我目前正在調查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