Skip to content
Advertisement

I Call API from PYTHON I get the response 406 Not Acceptable

I created a API in my site and I’m trying to call an API from python but I always get 406 as a response, however, if I put the url in the browser with the parameters, I can see the correct answer

I already did some test in pages where you can tests you own API, I test it in the browser and work fine. I already followed up a manual that explains how to call an API from python but I do not get the correct response :(

This is the URL of the API with the params: https://icassy.com/api/login.php?usuario_email=warles34%40gmail.com&usuario_clave=123

This is the code I use to call the API from Python

JavaScript

and I get:

JavaScript

I should receive in JSON format the success message and the apikey like this:

{“message”:”Successful login.”,”apikey”:”eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9leGFtcGxlLm9yZyIsImF1ZCI6Imh0dHA6XC9cL2ljYXNzeS5jb20iLCJpYXQiOjEzNTY5OTk1MjQsIm5iZiI6MTM1NzAwMDAwMCwiZGF0YSI6eyJ1c3VhcmlvX2lkIjoiMzQiLCJ1c3VhcmlvX25vbWJyZSI6IkNhcmxvcyIsInVzdWFyaW9fYXBlbGxpZG8iOiJQZXJleiIsInVzdWFyaW9fZW1haWwiOiJ3YXJsZXMzNEBnbWFpbC5jb20ifX0.bOhrC-vXhQEHtbbZGmhLByCxvJY7YxDrLhVOfy9zeFc”}

Advertisement

Answer

Looks like there is a validation on the server to check if request is made from some browser. Adding a user-agent header should do it –

JavaScript

This link of user agents might come handy in future.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement