10 Sep 2020
02:49 AM
- last edited on
25 May 2021
03:37 AM
by
MaciejNeumann
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
Solved! Go to Solution.
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