RuntimeError: Задача получила неправильный выход: <tornado.concurrent.Future объект в 0x11b3df048> - PullRequest
0 голосов
/ 16 мая 2019

Когда я спросил API с Почтальоном, я получил ошибку.Ошибка: "RuntimeError: Task got bad yield: <tornado.concurrent.Future object at 0x11b3df048>"

Код (python3.7 tornado)

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>

Ответы [ 2 ]

0 голосов
/ 19 июня 2019

Попробуйте что-то вроде этого:

from tornado.platform import asyncio
response = await asyncio.to_asyncio_future(tornado.httpclient.AsyncHTTPClient().fetch(request))

вместо

response = await tornado.httpclient.AsyncHTTPClient().fetch(request)
0 голосов
/ 17 мая 2019

Я думаю, это означает, что вы используете старую версию Tornado в сочетании с чем-то, что использует asyncio, без установки интеграции asyncio.Обновите tornado до последней версии или добавьте tornado.platform.install () в начало вашей программы.

...