【发布时间】:2018-04-27 08:13:36
【问题描述】:
使用 test_client 并像这样发送请求:
app = Flask(__name__)
client = app.test_client()
headers = {'content-type': 'application/json', 'Authorization': u'Bearer fake_token_123'}
params = {'dont_care': True}
client.get(ֿֿ'/my_route/123', query_string=params, headers=headers)
我的路线是
class MyController(Resource):
def get(self, id):
parser = reqparse.RequestParser()
parser.add_argument('currency', type=str, default='USD', help="help text")
args = parser.parse_args()
currency_from_params = args.currency
parser.parse_args() 失败
The browser (or proxy) sent a request that this server could not understand
当从标题中删除'content-type': 'application/json' 时它可以工作。
我不理解这种行为,如果没有不优雅的try, expect,我该如何防范它。
感谢您的帮助
【问题讨论】:
标签: python flask flask-restful