我有一个用Python 2.7编写的Web服务,它使用Falcon框架。一种特殊方法接受json值的帖子。我的代码:
def on_post(self, req, resp):
response = dict()
try:
data = simplejson.load(req.stream.read().decode("utf-8"))
logger.info(data)
mapUrl = data['url']
#mapUrl = req.get_params("url", None)
response['url'] = add_google_key(mapUrl)
resp.status = falcon.HTTP_200
resp.body = simplejson.dumps(response)
except Exception, ex:
response['error'] = "Error occured"
resp.status = falcon.HTTP_400
resp.body = simplejson.dumps(response)
return resp
我已尝试过很多我在Stack和Google上发现但没有变化的东西。我正在使用pycharm IDE,它只是在执行时超时
simplejson.load(req.stream.read().decode("utf-8"))
我尝试过的所有其他事情都没有读过json
json.loads(req.stream.read().decode("utf-8"))
卷曲请求我正在尝试
POST /add HTTP/1.1
Host: 127.0.0.1:8000
Content-Type: application/json
Cache-Control: no-cache
{
"url": "www.google.com"
}
环境:OSX Sierra Python 2.7 Falcon 0.3.0和其他版本是Pip的最新版本