10 Sep 2020
	
		
		10:49 AM
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 - last edited on 
    
	
		
		
		16 Oct 2023
	
		
		03:20 PM
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 by 
				
		
		
			random_user
		
		
		
		
		
		
		
		
	
			
		
I get an invalid syntax trying to use the requests library in Python. I've used the same syntax as this: https://community.dynatrace.com/questions/241885/how-to-get-data-from-dynatrace-api-using-python-re....
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.
10 Sep 2020 11:00 AM
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