Request to API Flask-Restful with JWT header and JSON data -


i'm trying following python:

this work:

curl -i -h "content-type: application/json" -h "accept: application/json" -x  -d "{\"dato\":\"1\"}" http://localhost:5000/api/v1/recurso -h " authorization: jwt ...p_gws2xoay"  

my resource:

class recursoprivado(resource):  @jwt_required() def get(self):     json_data = request.get_json(force=true)     #data  = json.loads(json_data)     return json_data  api.add_resource(recursoprivado, '/recurso') 

i tried this, return response [401]

url = 'http://localhost:5000/api/v1/recurso' data={"dato":"1"} token="...p_gws2xoay"  response=requests.get(url, data=data, headers={'authorization':'jwt '+token}) 

any ideas?

response = requests.get(url, data=data, headers={'authorization': 'jwt '+token}) 

should this:

response = requests.get(url, json=data, headers={'authorization': 'jwt '+token}) 

you're sending form-encoded data rather json-encoded data.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -