【问题标题】:WinError 10061: No connection could be made because the target machine actively refused it [InfluxDB with Flask]WinError 10061:无法建立连接,因为目标机器主动拒绝它[InfluxDB with Flask]
【发布时间】:2019-02-27 12:38:24
【问题描述】:

好的,所以我正在尝试为烧瓶设置 influxdb。
由于已经有 library 这样做了,所以我尝试尝试一下。
我查看了自述文件引用的示例目录,所以这就是我最终得到的:

from flask_influxdb import InfluxDB
from flask import Flask, render_template

app = Flask(__name__)
app.config['SECRET_KEY'] = 'applesandpears'
influx_db = InfluxDB(app=app)


@app.route('/newdb/<dbname>')
def newdb(dbname):
    dbcon = influx_db.connection
    dbcon.create_database(dbname)
    return ''


@app.route('/write/<dbname>')
def write(dbname):
    data_measurement = 'testseries'
    data_tags = ['time', 'value_1', 'value_2', 'value_3']

    dbcon = influx_db.connection
    dbcon.switch_database(database=dbname)
    dbcon.write_points([
        {
            "fields": {
                'value_1': 0.5,
                'value_2': 1,
                'value_3': 1.8858
            },
            "tags": {
                'tag_1': 'tag_string',
                'tag_2': 'tag_string'
            },
            "measurement": "testseries"
        }
    ])
    tabledata = dbcon.query('SELECT {0} from {1}'.format(', '.join(data_tags), data_measurement))

    data_points = []
    for measurement, tags in tabledata.keys():
        for p in tabledata.get_points(measurement=measurement, tags=tags):
            data_points.append(p)

    return render_template('table.html',
                           measurement=data_measurement,
                           columns=data_tags,
                           points=data_points)


if __name__ == '__main__':
    app.run(debug=True)

当我尝试以下查询 http://localhost:5000/newdb/testdb 时,我收到以下错误:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8086): Max retries exceeded with url: /query?q=CREATE+DATABASE+%22testdb%22 (Caused by NewConnectionError('&lt;urllib3.connection.HTTPConnection object at 0x0000013DF2AB7E10&gt;: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))

创建数据库的封装代码可以在here找到

现在,我了解到这不是特定于 influx-db 的错误,而是 Windows 错误。我浏览了其他文章并尝试禁用防火墙,但这似乎不起作用。我也尝试以管理员身份运行 cmd ,但同样没有任何反应。

似乎是什么问题?

【问题讨论】:

  • 你的 influxdb 运行了吗?您可以在命令行中使用 influx 并创建数据库吗?计时码表是否成功连接到您的数据库?如果 db 工作正常,我建议使用 Pinform (github.com/sinarezaei/pinform) 或 Python-InfluxDB (github.com/influxdata/influxdb-python) 并检查它们是否会导致类似的错误,但我认为这更多的是连接问题

标签: python windows flask flask-sqlalchemy influxdb


【解决方案1】:

这可能是因为代理。您需要指定代理设置 您的代码或项目的入口点。

import os #for proxy

proxy = 'http://10.XX.XX.XX:8X8X' #your own proxy 'http://<user>:<pass>@<proxy>:<port>'

os.environ['http_proxy'] = proxy 
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
#rest of code .....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 2020-07-07
    • 2021-01-04
    • 2020-06-26
    • 2021-11-10
    • 2018-12-01
    相关资源
    最近更新 更多