Error processing Json request
我正在发送一个JSON请求,并在python flask服务中捕获请求参数以进一步处理。但是,当我json转储请求并尝试从中收集特定的参数值时,它会给我带来错误。
字符串索引必须是整数,而不是str
这是我在python flask中解析的json:
1 2 3 4 5 | {"description":"URL: https://sometest.xyz.com/test16/apicall\ Issue: sample issue\ Result: fail\ Severity: low\ Category: sample category","issuetype": {"name":"Bug"},"priority": {"name":"Trivial"},"project":"sample-project","summary":"sample issue - https://sometest.xyz.com/test16/apicall"} |
我不知道我在做什么。
这是我的python flask代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from flask import Flask from flask import request from flask import json import httplib httplib.HTTPConnection.debuglevel = 2 app = Flask(__name__) @app.route('/', methods=['POST','GET']) def main(): _jsonreq = json.dumps(request.json) return _jsonreq['project'] if __name__ =="__main__": app.run(debug=True) |
您正在为
1 2 3 4 | @app.route('/', methods=['POST','GET']) def main(): _jsonreq = request.json return _jsonreq['project'] |