11

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')]
davidism
  • 121,510
  • 29
  • 395
  • 339
MakleBirt
  • 561
  • 1
  • 6
  • 18
  • Your code looks fine. Did you import `request` from flask? – Bidhan Jun 02 '15 at 03:28
  • I am importing: from app import app from flask import Flask, request, jsonify, Response, stream_with_context, make_response from flask.ext.sqlalchemy import SQLAlchemy from sqlalchemy import Column, Integer, String, DateTime, Float import cStringIO import csv import datetime – MakleBirt Jun 02 '15 at 03:35
  • 127.0.0.1 - - [01/Jun/2015 21:35:10] "GET /path?param1=1 HTTP/1.1" 200 - – MakleBirt Jun 02 '15 at 03:39
  • Flask isn't getting the second parmeter in the URL itself. Are you sure you are sending the right URL? – Bidhan Jun 02 '15 at 03:46
  • Are you using curl to make the request? – dirn Jun 02 '15 at 03:58
  • I am using curl. My request looks like: curl localhost:5000/path?param1=1&param2=2 – MakleBirt Jun 02 '15 at 04:04
  • 5
    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 Jun 02 '15 at 04:07
  • 1
    Wow! Thanks Bidhan! That wasted so much time. – MakleBirt Jun 02 '15 at 04:12
  • Lol. No problem. I went through something similar a while back and it left me frustrated for a long time. I'm glad you got that sorted out. Good luck. – Bidhan Jun 02 '15 at 04:14

1 Answers1

25

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

To quote:

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

Community
  • 1
  • 1
MakleBirt
  • 561
  • 1
  • 6
  • 18