【发布时间】:2017-07-24 15:53:27
【问题描述】:
我目前正在研究 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())
【问题讨论】:
-
你确定确定你使用的是python 3.5吗?
-
$ python3 Python 3.5.2(默认,2016 年 11 月 17 日,17:05:23)
-
试试
from pulsar.apps.http import HttpClient和async with HttpClient()看看错误是否改变。 -
触发上述错误的具体命令是什么?
-
@BrandonIbbotson 我按照建议尝试,得到相同的错误异步 with HttpClient() as session: 我标记了 ^ 的位置
标签: python python-3.x asynchronous python-pulsar