对Flask中的请求JSON进行故障排除

时间:2019-03-01 19:28:58

标签: json python-2.7 flask unicode

我的Flask Web服务具有以下代码:

@app.route('/api/my_service', methods=['GET', 'POST'])
def my_service():
    try:
        content = request.get_json()
        print type(content)
        print 'content', content
    except:
        print sys.exc_info()

我的客户称此为

input = {'my_key': 1, 'other_key': 2}
url ='http://local:5000/api/my_service'
res = requests.post(url, json=input)
if res.ok:
    print res.text

输出是这个     
     内容{u'my_key':1,1,u'other_key':2}

看来我的词典转换不正确。我该如何解决?

0 个答案:

没有答案
相关问题