好的,我正在尝试为烧瓶设置influxdb。
由于已经有library可以做到这一点,所以我尝试了一下。
我遍历了README引用的示例目录,所以最终得到的是:
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('<urllib3.connection.HTTPConnection object at 0x0000013DF2AB7E10>: 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,但是再次没有任何反应。
问题出在哪里?
答案 0 :(得分:0)
这可能是由于代理。您需要在以下位置指定代理设置 您的代码或项目的入口点。
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 .....