python请求dynatrace SAAS url超过最大重试次数

时间:2019-09-16 20:21:36

标签: python python-requests dynatrace

尝试使用python3脚本从Dynatrace SAAS获取用户会话数据。 get Request给我错误Max retries exceeded with url: Failed to establish a new connection:

我不确定是否传递令牌或代理错误。

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',))

但是 我可以使用CURL和来自同一台计算机的代理来获取数据。

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

谢谢!

1 个答案:

答案 0 :(得分:0)

您确定代理位于http而非https下吗?如果是这样,请尝试以以下方式发送api令牌:

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

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

前缀r确保您正在发送原始字符串数据。