-1

I have response object as <Request 'http://xx.xx.xx.xx/pipelineInfo' [GET]>and i am trying to get data from the request object as

request.json.get('xxx',NONE)

and also as

request.get('XXX',NONE) 

but failed to get a response and getting an error as

Exception : 'Request' object has no attribute 'get' and Exception : 'Request' object has no attribute 'json'.

Can someone suggest me what the issue will be?

5
  • You must initiate this header while sending data as json Content-Type: application/json Commented Sep 14, 2017 at 9:27
  • Actually i have working with one of the code provided by some other person.Currently i dont have contact with that person and even we dont know how data is sending by them and services written by them.onli i have an option to get the data from that. Commented Sep 14, 2017 at 9:29
  • Can you tell me how you are requesting this service? when you are getting this exception. Commented Sep 14, 2017 at 9:30
  • Try this post: stackoverflow.com/questions/10320307/… Commented Sep 14, 2017 at 9:41
  • request.args.get is not giving error but giving none value Commented Sep 14, 2017 at 9:48

2 Answers 2

0

you need use args property reqcontext

request.args.get('XXX')

or get_json

request.get_json().get('XXX')
Sign up to request clarification or add additional context in comments.

Comments

0

If the data sent in the request is json, you can use json_data = request.get_json() However,this function will return None if the mimetype is not application/json, but this can be overridden by the force parameter.

json_data = request.get_json(force=True)

An alternative way to get json data is:

json_data = json.loads(request.data) as well.

Other ways of getting data from request can be found in this question: How to get data received in Flask request

Also, please do have a look at official documentation(http://flask.pocoo.org/docs/0.12/api/#flask.Request.get_json)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.