influxdata / influxdata/influxdb

Getting permission denied error when trying to write to influx

Open
#23,954 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

I am very new to influxdb and I am struggling to write sample data to a dev influxdb via python. I have a retention policy set to INF with replication factor 2. My code is written in python and loops through a list of pandas of items that formats each line item as a point to be written to the db using line protocol formatting.

I keep getting the following error when attempting to write to influxdb:

influxdb.exceptions.InfluxDBServerError: {"error":"write failed: mkdir /data/database_name: permission denied"}

Sample code:

df['tag_id1'] = df['tag_id1'].astype("string")
df['tag_id2'] = df['tag_id2'].astype("string")
df['tag_id3'] = df['tag_id3'].astype("string")
df['field_id1'] = df['field_id1'].astype("float")
df['field_id2'] = df['field_id2'].astype("float")

empty_list = []

for idx, row in df.iterrows():
    tag_id1 = df['tag_id1'].astype("string")
    tag_id2 = df['tag_id2'].astype("string")
    tag_id3 = df['tag_id3'].astype("string")
    tag_id3 = tag_id3.replace(" ", "\\ ") -- this handles a space in a datetime object being written as a string; do not want these to be indexed timestamps
    field_id1 = df['field_id1'].astype("float")
    field_id2= df['field_id2'].astype("float")
    measurement = config['DATABASE']['Measurement']
    write_time = dt.utcnow()
    utc_unix_timestamp = calendar.timegm(write_time.utctimetuple())

    empty_list.append(f'{measurement},tag_id1="{tag_id1}",tag_id2="{tag_id2}",tag_id3="{tag_id3}" field_id1={field_id1},field_id2={field_id2} {utc_unix_timestamp}')

  client = InfluxDBClient(host=config['SERVER']['Hostname'], 
                      port=config['SERVER']['Port'], 
                      username=config['LOGIN']['Username1'], 
                      password=config['LOGIN']['Password1'],
                      database=config['DATABASE']['Database'],
                      ssl=True, 
                      verify_ssl=False)

  for x in empty_list: 
      client.write_points(
                      x, 
                      time_precision='n', 
                      database=config['DATABASE']['Database'], 
                      retention_policy=config['DATABASE']['Retention_Policy'], 
                      protocol=u'line', 
                      consistency='all')

I think my spacing is correct for the line protocol formatting. On my end, it looks like the influx client is attempting to read, then write each point, but is getting stuck on something and denying me permission. I have also seen partial write errors and also what looks like my tags being recognized, but not my fields. Not sure where to go look next but I'm struggling to find a solution to get these points written to the influxdb. I'm trying to keep this line protocol format because when using json protocol and writing directly from pandas gives me python deprecation warnings. Thanks for any help.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Python client construction and the client.write_points calls in the sample, then compare them with the server error showing that creating /data/database_name is denied. Check the InfluxDB server-side write path and permissions, and use the reported partial-write and tag/field behavior to determine whether the failure is storage access or line-protocol formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.