使用 Datadog API 執行 Python 腳本時 SNI 缺少警告

使用 Datadog API 執行 Python 腳本時 SNI 缺少警告

我是一名初學者,我完全陷入了這個困境。我嘗試了許多不同的解決方案,但尚未找到有效的解決方案,您能幫助我嗎? :)

我在 VirtualBox 上使用 Vagrant 創建了一個 Ubuntu 12.04 VM,並在其上安裝了 Datadog 代理。然後,我創建了一個 Datadog API 腳本來建立具有不同圖表的時間板。我正在嘗試執行 python 腳本,但每次都會收到警告,但沒有結果。正如你在這裡看到的:https://docs.datadoghq.com/api/?lang=python#create-a-timeboard 我應該能夠在 Datadog 儀表板中看到時間板,但它沒有出現。

這是我在 /home/datadog 中創建的腳本:

#!/usr/bin/env python

from datadog import initialize, api

options = {
    'api_key': 'MYAPIKEY',
    'app_key': 'MYAPPKEY'
}

initialize(**options)

title = "Visualizing Data for Barbosa"
description = "Timeboard using Datadog's API"
graphs = [

{
    "definition": {
        "events": [],
        "requests": [
            {"q": "my_metric{host:precise64}"}
        ],
        "viz": "timeseries"
    },
    "title": "My metric scoped over my host"
},

{
    "definition": {
        "events": [],
        "requests": [
            {"q": "anomalies(avg:mysql.performance.cpu_time{host:precise64}, 'robust', 2)"}
        ],
        "viz": "timeseries"
    },
    "title": "Anomalies on MySQL for CPU time"

},

{
    "definition": {
        "events": [],
        "requests": [
            {"q": "avg:ùy_metric{host:precise64}.rollup(sum, 3600)"}
    ],
        "viz": "timeseries"
    },
    "title": "Rollup for My metric over the past hour"

}]

read_only = True
api.Timeboard.create(title=title,
                     description=description,
                     graphs=graphs,
                     read_only=read_only)

當我使用執行腳本時,/home/datadog$ ./timeboard.py我得到以下資訊:

/usr/local/lib/python2.7/dist-packages/urllib3/util/ssl_.py:339: 
SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name 
Indication) extension to TLS is not available on this platform. This may 
cause the server to present an incorrect TLS certificate, which can cause 
validation failures. You can upgrade to a newer version of Python to solve 
this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-
usage.html#ssl-warnings.
SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/urllib3/util/ssl_.py:137: 
InsecurePlatformWarning: A true SSLContext object is not available. This 
prevents urllib3 from configuring SSL appropriately and may cause certain 
SSL connections to fail. You can upgrade to a newer version of Python to 
solve this. For more information, see 
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings.
InsecurePlatformWarning

我嘗試升級 python,但是當使用 Python 3 執行程式碼時,它不再識別 Datadog python 套件(https://github.com/DataDog/datadogpy)並且我不知道如何將其從 Python 2.7 中移出,或者刪除 Python 2.7 是否會導致我的程式碼/腳本出現巨大問題。我是初學者,如果這令人困惑,我很抱歉!

我也嘗試過以下https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings但不幸的是導入命令也不起作用,是否需要安裝特定的軟體/軟體包才能使其工作?

我究竟做錯了什麼?謝謝!

答案1

答案是透過直接在 python 腳本中加入 import... 來刪除警告,如中所述stackoverflow.com 上的這個答案

相關內容