Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I am trying to get determine if I am passing an object key value pair to a get request in a python rest api. I have the following:
- @app.route('/', methods=['GET', 'DELETE', 'POST'])
- def profits():
- if request.method=='GET':
- if 'listname' in request.json:
- print 'inside listname == True!!!'
- conn = psycopg2.connect(database = "profitnloss3", user = "patientplatypus", password = "Fvnjty0b")
- cur = conn.cursor()
- sql = 'SELECT * FROM ledger WHERE listname = %s'
- params = (request.json['listname'])
- cur.execute(sql, params)
- conn.commit()
- data = cur.fetchall()
- conn.close()
- return jsonify(data)
- else:
- print 'inside listname == False!!!'
- conn = psycopg2.connect(database = "profitnloss3", user = "patientplatypus", password = "Fvnjty0b")
- cur = conn.cursor()
- sql = 'SELECT * FROM ledger'
- cur.execute(sql)
- conn.commit()
- data = cur.fetchall()
- conn.close()
- return jsonify(data)
- Which I call on my front end with an axios call
- axios({
- method: 'get',
- url: 'http://localhost:5000/',
- headers: {
- 'Content-type': 'application/json'
- },
- data:{
- 'listname': this.ledgername
- }
- })
- .then((response)=>{
- console.log('this is the response from the python server on a get request of listname ', response);
- })
- .catch(error=>{
- console.log('here is the error on a get request from the python server of listname ', error);
- })
- But the error I get is:
- Traceback (most recent call last):
- File "/home/patientplatypus/vuespring/backend_PYTHON3/env/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
- response = self.full_dispatch_request()
- File "/home/patientplatypus/vuespring/backend_PYTHON3/env/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
- rv = self.handle_user_exception(e)
- File "/home/patientplatypus/vuespring/backend_PYTHON3/env/local/lib/python2.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
- return cors_after_request(app.make_response(f(*args, **kwargs)))
- File "/home/patientplatypus/vuespring/backend_PYTHON3/env/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
- reraise(exc_type, exc_value, tb)
- File "/home/patientplatypus/vuespring/backend_PYTHON3/env/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
- rv = self.dispatch_request()
- File "/home/patientplatypus/vuespring/backend_PYTHON3/env/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
- return self.view_functions[rule.endpoint](**req.view_args)
- File "/home/patientplatypus/vuespring/backend_PYTHON3/main.py", line 50, in profits
- if 'listname' in request.json:
- File "/home/patientplatypus/vuespring/backend_PYTHON3/env/local/lib/python2.7/site-packages/werkzeug/local.py", line 379, in <lambda>
- __contains__ = lambda x, i: i in x._get_current_object()
- TypeError: argument of type 'Request' is not iterable
- My google fu is failing me, but I suspect that python is somehow not allowed to look through the request list by looping through it. However I have seen other people on stackoverflow say that similar things will work. What am I not seeing?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement