2

Trying to get User session data from Dynatrace SAAS using python3 script. The get Request is giving me error Max retries exceeded with url: Failed to establish a new connection:

I'm not sure if I'm passing the token or proxy wrong.

import requests
from requests.exceptions import ConnectionError

try:
    response = requests.get('https://jbu0001.live.dynatrace.com/api/v1/userSessionQueryLanguage/table?SELECT%20*%20from%20usersession&explain=true',
                           headers={'Authorization': 'Api-Token XXXXXXXX'}, proxies={'http': 'http://proxy.com:PORT'}, verify=False)
    if response.status_code == 200:
        response.text
except ConnectionError as e:
    print(e)

ERR0R

HTTPSConnectionPool(host='jbu0000.live.dynatrace.com', port=443): Max retries exceeded with url: /api/v1/userSessionQueryLanguage/table?SELECT%20*%20from%20usersession&explain=true (Caused by NewConnectionError('<urllib3.conne
ction.VerifiedHTTPSConnection object at 0x00000160212D5B38>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

BUT I'm able to get data using CURL with proxy from same machine.

curl -X GET "https://jbu00XXX.live.dynatrace.com/api/v1/userSessionQueryLanguage/table?query=select%20*%20from%20usersession&explain=true" -H "accept: application/json" -H "Authorization: Api-Token XXXXXXXXX" --proxy http://proxy.com:PORT

Thanks in advance!

mani
  • 23
  • 3

1 Answers1

0

Are you sure that proxy is under http not https? If so, try sending api-token as:

 headers={'Authorization': r'Api-Token XXXXXXXX'}

or

 headers={'Authorization': r'XXXXXXXX'}

prefix r assures that you are sending raw string data.

Misieq
  • 507
  • 2
  • 12