cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get data from Dynatrace API using Python Requests module

volkan_eruyandi
Participant

Hi,

I'm trying to pull some data over REST API of our managed Dynatrace cluster(1.196.80.20200709-090917). I'm using Python (3.6.8) and Requests (2.23.0) library.

I'm able to get the problem feed with the curl command below, but it fails with Python.

I even installed requests_debugger module and printed out the corresponding curl command, and it prints a successful curl command, however it fails when i run the Python script.

Can you please help?

I tried to run the same script on the cluster node, it failed again.

1st trial:


2nd trial: (the only diff is r = requests.get(url, headers={ 'Authorization': ' Api-Token gNePSMwLQVSKZeLEOPkx4' }) with a leading space in ' Api-Token...' I do it to reproduce the same curl command which works.

I tried also other combinations, none of them worked. As you can see the curl command at the last line gets HTTP 200 with the problem feed in his response.

requests library doesn't let the leading space for security reasons. What can i do, i want to use both (python and requests, it is easy.)

2 REPLIES 2

dave_mauney
Dynatrace Champion
Dynatrace Champion

I use requests all the time.

Here is my python code that uses requests:

resp = requests.get(full_url, headers={'Authorization': "Api-Token " + token})

I think you have something wrong with quotes...

volkan_eruyandi
Participant

Hi Dave,

Thank you for your comment but I've found out that the error is due to Python requests which does not trust our own custom certificate that we generated for our Dynatrace managed cluster. It is not signed by CA it is only trusted in my company network.

I added the path to my full certificate file (including all certificate chain, sub and root) and it worked.

requests.get(url, headers={'Authorization': "Api-Token " + token} , verify='/etc/pki/ca-trust/source/anchors/dynatrace_cert.pem')

Featured Posts