龙卷风异步发布错误500但卷曲确定

时间:2016-07-24 18:11:49

标签: python tornado

网址为http://*.*.*.*/100/?id=1&version=1

params是

{"cityId": "110000", "query": {"queryStr": "line1", "queryExp": ""}, "channelId": "house"}

curl命令是:

curl -X POST -H "Content-Type: application/json" -d '{"cityId": "110000", "query": {"queryStr": "line1", "queryExp": ""}, "channelId": "house"}' "http://*.*.*.*/100/?id=1&version=1"

但是当我使用龙卷风(4.2)AsyncHTTPClient时,我收到了错误:

tornado.application:Future exception was never retrieved: Traceback (most recent call last):
...
HTTPError: HTTP 500: Internal Server Error

我这样要求:

@gen.coroutine
def request(self, url, method="GET", headers=None, data=None):
    logger.debug(method)
    logger.debug(headers)
    logger.debug(data)
    headers = {
        'content-type': 'application/json',
    }
    req = HTTPRequest(
        url,
        method=method,
        headers=headers,
        body=urllib.urlencode(data).encode('utf-8')
    )
    http_response = yield self.r.fetch(
        # req,
        # self.handle_request
        url,
        method=method,
        headers=headers,
        body=urllib.urlencode(data).encode('utf-8')
    )
    # logger.debug(http_response)
    raise gen.Return(json.loads(http_response.body))

1 个答案:

答案 0 :(得分:0)

您正在发送'content-type': 'application/json',,但使用body=urllib.urlencode(data).encode('utf-8')对数据进行编码。使用json.dumps代替urllib.urlencode