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

Python Requests fail

Lisa_Singh01
Participant

I get an invalid syntax trying to use the requests library in Python. I've used the same syntax as this: https://answers.dynatrace.com/questions/241885/how-to-get-data-from-dynatrace-api-using-python-re.ht...

import requests

URL = "https://somehostname.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin%3Asynthetic.browser.totalDuration&from=now-2d&to=now-1d")
headers = {'Authorization': "Api-Token " + 123456Token123456}

r = requests.get(url, headers=headers)
print(r)


But get invalid syntax errors:


Traceback (most recent call last):
  File "C:\Users\leica\Documents\Python\muckingabout.py", line 3
    URL = "https://somehostname.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin%3Asynthetic.browser.totalDuration&from=now-2d&to=now-1d")
                                                                                                                                                   ^
SyntaxError: invalid syntax

 

1 REPLY 1

Mike_L
Dynatrace Pro
Dynatrace Pro

Hi,

Please remove the trailing ')' from your code on line three (the end of the URL) as it fails to compile due to that one.

Once that's resolved it will also fail on line 4 as the API token needs to be within the quotes, it's not a variable.

Mike