Reputation: 97
When try to write the data into influxDB using influxDB client. i am getting the below error. I was able to login to the influxDB web browser using http://localhost:8086
with the same credentials provided in the code. But facing with the unauthorized message when using python code. any help would be appreciated.
Error: raise InfluxDBClientError(err_msg, response.status_code) influxdb.exceptions.InfluxDBClientError: 401: {"code":"unauthorized","message":"Unauthorized"}
Code:
from influxdb import InfluxDBClient
from datetime import datetime
client = InfluxDBClient('localhost', 8086, 'username', 'password', 'bucket_name')
for row in df.iterrows():
influxJson = [
{
"measurement":"testing123",
"time" : datetime.utcnow().isoformat() + "Z",
"tags": {
'ResiliencyTier':'targetResiliencyTier',
'lob' : 'abcdefgh'
},
"fields": {
columns[0][0] : str(row[1][0]),
columns[1][0] : str(row[1][1]),
}
}
]
client.write_points(influxJson)
print("InfluxDB injection DONE")
startProcess()
Thanks
Upvotes: 2
Views: 16720
Reputation: 538
Error code 401 (unauthorized) can be avoided in dev env by enabling http access in influx config file:
[http]
# Determines whether HTTP endpoint is enabled.
enabled = true
genarally config file can be found at:
/etc/influxdb/influxdb.conf
Upvotes: 1