influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
706 stars 185 forks source link

import netmiko will get an errror: TypeError: 'NoneType' object is not callable #615

Closed blcoffee closed 10 months ago

blcoffee commented 10 months ago

Specifications

Code sample to reproduce problem

import influxdb_client, os, time
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
import netmiko
token = os.environ.get("INFLUXDB_TOKEN")
org = "test"
url = "http://10.0.0.178:8086"

write_client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)
write_api = write_client.write_api(write_options=SYNCHRONOUS)
bucket="python"

point = (
    Point("measurement1")
    .tag("tagname1", "tagvalue1")
    .field("field1", 111)
    .field("field2", 222)
  )
write_api.write(bucket=bucket, org="test", record=point) 

Expected behavior

write the vaule get via netmiko to DB without error.

Actual behavior

If I import netmiko I will get this error:

Exception ignored in: <function InfluxDBClient.__del__ at 0x109564310>
Traceback (most recent call last):
  File "/Users/blcoffe/.pyenv/versions/3.9.16/envs/py3.9/lib/python3.9/site-packages/influxdb_client/client/influxdb_client.py", line 320, in __del__
  File "/Users/blcoffe/.pyenv/versions/3.9.16/envs/py3.9/lib/python3.9/site-packages/influxdb_client/_sync/api_client.py", line 84, in __del__
  File "/Users/blcoffe/.pyenv/versions/3.9.16/envs/py3.9/lib/python3.9/site-packages/influxdb_client/_sync/api_client.py", line 661, in _signout
TypeError: 'NoneType' object is not callable
Exception ignored in: <function ApiClient.__del__ at 0x10a6569d0>
Traceback (most recent call last):
  File "/Users/blcoffe/.pyenv/versions/3.9.16/envs/py3.9/lib/python3.9/site-packages/influxdb_client/_sync/api_client.py", line 84, in __del__
  File "/Users/blcoffe/.pyenv/versions/3.9.16/envs/py3.9/lib/python3.9/site-packages/influxdb_client/_sync/api_client.py", line 661, in _signout
TypeError: 'NoneType' object is not callable

Additional info

The workaround is put "import netmiko" after write_client.write_api(write_options=SYNCHRONOUS) and we won't get an error.

import influxdb_client, os, time
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

token = os.environ.get("INFLUXDB_TOKEN")
org = "test"
url = "http://10.0.0.178:8086"

write_client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)
write_api = write_client.write_api(write_options=SYNCHRONOUS)

import netmiko

bucket="python"

point = (
    Point("measurement1")
    .tag("tagname1", "tagvalue1")
    .field("field1", 111)
    .field("field2", 222)
  )
write_api.write(bucket=bucket, org="test", record=point) 
Sciator commented 10 months ago

I wasn't able to replicate issue using said versions of influxdb client and influxdb on linux nor windows. Using above snippets write goes through but is duplicated. Write works fine without netmiko import. As it seems there is no indication that problem is on our side. Try contancting netmiko for fix if you want to use their library.

wyn-ying commented 9 months ago

i meet the same issue, without using netmiko.

it seems that "influxdb_client/_sync/api_client.py", line 661, in :func:_signout could not find :func:_requires_expire_user_session correctly.

i just copy :func:_requires_expire_user_session from "influxdb_client/rest.py" to :func:_signout as an inner function, then fix the TypeError Execption. :func:_signout seems to be like:

    def _signout(self):
        def _requires_expire_user_session(configuration: Configuration, cookie: str):
            return configuration.username and configuration.password and cookie

        if _requires_expire_user_session(self.configuration, self.cookie):
            SignoutService(self).post_signout()
            self.cookie = None

Client Version: 1.38.0 InfluxDB Version: v2.7.1 Platform: Linux Python Version: 3.11

Also import pymongo before initializing write_client and write_api