Search code examples
pythongetpostmanaccess-token

GET request via python script with access token


I'm facing some difficulties executing GET request with access token via python. For some reason when I execute the request from POSTMAN I get the expected result, however, when using python I get connection error :

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

I believe that my script is being blocked by the server to prevent scrapping attempts, but I'm not sure. This is what I'm running via POSTMAN :

https://www.operation.io/web/alerts?access_token=6ef06fee265de1fa640b6a444ba47--z&envId=58739be2c25e76a202c9dd3e&folderId=active&sortBy=status

And this is what I'm running from inside the script :

response = requests.get('https://www.operation.io/web/alerts', headers={'Authorization': 'access_token 6ef06fee265de1fa640b6a444ba47--z'})

Please notice that the url and the access token are not real, so please don't try to use. How can I make it work via the script and not only via postman? Thank you for your help/


Solution

  • It's hard to tell without actually being able to test the solutions, but I would suggest 2 hacks that worked for me in the past:

    1. Change "Authorization" to "authorization"
    2. Change "6ef06fee265de1fa640b6a444ba47--z" to "Token 6ef06fee265de1fa640b6a444ba47--z" (add a space as well)

    Put it all together:

    response = requests.get('https://www.operation.io/web/alerts', headers={'authorization': 'Token 6ef06fee265de1fa640b6a444ba47--z'})