Flask仅查看通过curl发送的多个参数中的第一个参数 [英] Flask only sees first parameter from multiple parameters sent with curl

查看:50
本文介绍了Flask仅查看通过curl发送的多个参数中的第一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用curl向需要多个查询参数的Flask路由发出请求.但是,日志仅显示网址中的第一个参数,而Flask没有看到第二个参数.怎么了?

I am using curl to make a request to a Flask route that expects multiple query params. However, the log shows only the first param in the url, and Flask doesn't see the second param. What is going wrong?

@app.route('/path', methods=['GET'])
def foo():
    print request.args.get('param2')
    req = request.args.items()
    print req

curl http://localhost:5000/path?param1=1&param2=2

127.0.0.1 - - [01/Jun/2015 21:35:10] "GET /path?param1=1 HTTP/1.1" 200 -
None
[('param1', u'1')]

推荐答案

请参阅Bidhan的评论

See Bidhan's comment here. I was using curl without putting my URL inside double quotes.

引用:

如果您使用curl,则需要在引号内传递url.它看起来应该像 curl"localhost:5000/path?param1 = 1& param2 = 2" 一样.在外壳用于分叉过程,行为不像您会期望的.– Bidhan A

If you're using curl then you need to pass the url inside of quotes. It should look like curl "localhost:5000/path?param1=1&param2=2" . In the shell, & is used for forking processes and doesn't behave like you would expect it to. – Bidhan A

这篇关于Flask仅查看通过curl发送的多个参数中的第一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆