当我向Postman请求API时,出现了错误。
错误是"RuntimeError: Task got bad yield: <tornado.concurrent.Future object at 0x11b3df048>"
代码(python3.7龙卷风)
async def post_data(self, url, param_dict):
"""
send post requests
:param url:
:param param_dict:
:return:
"""
post_data = self._gen_request_data(param_dict)
headers = {"content-type": "application/json"}
import tornado.httpclient
request = tornado.httpclient.HTTPRequest(
url, method="POST", headers=headers, body=post_data, validate_cert=False
)
response = await tornado.httpclient.AsyncHTTPClient().fetch(request)
return response.body
完整错误输出:
[E 190516 10:34:31 basehandler:205] HTTPServerRequest(protocol='http', host='127.0.0.1:12601', method='POST', uri='/didiapp/ocr/submit?image=', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'Cache-Control': 'no-cache', 'Postman-Token': '7dc560ec-bb6d-4378-95a7-60dfed96d07c', 'User-Agent': 'PostmanRuntime/7.6.0', 'Accept': '*/*', 'Host': '127.0.0.1:12601', 'Accept-Encoding': 'gzip, deflate', 'Content-Type': 'multipart/form-data; boundary=--------------------------875189288125929592701049', 'Content-Length': '47337', 'Connection': 'keep-alive'})
Task got bad yield: <tornado.concurrent.Future object at 0x11b3df048>
Traceback (most recent call last):
File "/.pyenv/versions/3.7.1/lib/python3.7/site-packages/jplib3/basehandler.py", line 201, in process_module
await method.__call__()
File "/horus/service/thirdparty/pdd_express.py", line 79, in post_data
response = await tornado.httpclient.AsyncHTTPClient().fetch(request)
File "<string>", line 3, in __await__
RuntimeError: Task got bad yield: <tornado.concurrent.Future object at 0x11b3df048>
答案 0 :(得分:0)
我认为这意味着您将旧版本的Tornado与使用asyncio的东西结合使用,而没有安装asyncio集成。升级到龙卷风的最新版本,或将tornado.platform.install()添加到程序的开始。
答案 1 :(得分:0)
尝试这样的事情:
from tornado.platform import asyncio
response = await asyncio.to_asyncio_future(tornado.httpclient.AsyncHTTPClient().fetch(request))
相反:
response = await tornado.httpclient.AsyncHTTPClient().fetch(request)