matthewwall / weewx-influx

uploader for influxdb
GNU General Public License v3.0
45 stars 22 forks source link

Unable to have a hyphen in the influxdb database name #26

Open bdf0506 opened 3 years ago

bdf0506 commented 3 years ago

I was banging my head against a wall trying to figure out why this extension wasn't working properly - and it was because I was using a hyphen in the database name. It looks like the extension doesn't like that. I also tried encapsulating the db name in the config in quotes, but still no go. I don't think this is an influxdb limitation, but rather something with the extension that I can't figure out.

Jan 1 22:37:17 weewx[17] INFO user.influx: service version is 0.15

Jan 1 22:37:17 weewx[17] INFO user.influx: database is weewx-docker
Jan 1 22:37:17 weewx[17] INFO user.influx: tags None
Jan 1 22:37:17 weewx[17] INFO user.influx: binding is loop,archive
Jan 1 22:37:17 weewx[17] ERROR user.influx: create database failed: HTTP Error 400: Bad Request

Jan 1 22:37:17 weewx[17] INFO user.influx: Data will be uploaded to http://influxdb.home:8086
Jan 1 22:37:17 weewx[17] INFO __main__: Starting up weewx version 4.2.0

Jan 1 22:37:17 weewx[17] INFO weewx.engine: Using binding 'wx_binding' to database 'weewx.sdb'
Jan 1 22:37:17 weewx[17] INFO weewx.manager: Starting backfill of daily summaries
Jan 1 22:37:17 weewx[17] INFO weewx.engine: Starting main packet loop.
Jan 1 22:37:19 weewx[17] ERROR weewx.restx: Influx: Unexpected exception of type <class 'TypeError'>

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** Traceback (most recent call last):

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/home/weewx/bin/weewx/restx.py", line 475, in post_with_retries

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** _response = self.post_request(request, data)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/home/weewx/bin/user/influx.py", line 498, in post_request

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** return super(InfluxThread, self).post_request(request, payload)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/home/weewx/bin/weewx/restx.py", line 537, in post_request

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** _response = urllib.request.urlopen(request, data=data_bytes, timeout=self.timeout)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/usr/local/lib/python3.9/urllib/request.py", line 214, in urlopen

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** return opener.open(url, data, timeout)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/usr/local/lib/python3.9/urllib/request.py", line 523, in open

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** response = meth(req, response)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/usr/local/lib/python3.9/urllib/request.py", line 632, in http_response

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** response = self.parent.error(

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/usr/local/lib/python3.9/urllib/request.py", line 561, in error

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** return self._call_chain(*args)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/usr/local/lib/python3.9/urllib/request.py", line 494, in _call_chain

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** result = func(*args)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/usr/local/lib/python3.9/urllib/request.py", line 641, in http_error_default

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** raise HTTPError(req.full_url, code, msg, hdrs, fp)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** urllib.error.HTTPError: HTTP Error 404: Not Found

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: ***

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** During handling of the above exception, another exception occurred:

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: ***

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** Traceback (most recent call last):

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/home/weewx/bin/weewx/restx.py", line 381, in run_loop

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** self.process_record(_record, dbmanager)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/home/weewx/bin/weewx/restx.py", line 446, in process_record

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** self.post_with_retries(_request, data)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/home/weewx/bin/weewx/restx.py", line 496, in post_with_retries

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** self.handle_exception(e, _count + 1)

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** File "/home/weewx/bin/user/influx.py", line 486, in handle_exception

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** if payload and payload.find("error") >= 0:

Jan 1 22:37:19 weewx[17] ERROR weewx.restx: *** TypeError: argument should be integer or bytes-like object, not 'str'

Jan 1 22:37:19 weewx[17] CRITICAL weewx.restx: Influx: Thread terminating. Reason: argument should be integer or bytes-like object, not 'str'
Exception in thread Influx:
Traceback (most recent call last):
File "/home/weewx/bin/weewx/restx.py", line 475, in post_with_retries
_response = self.post_request(request, data)
File "/home/weewx/bin/user/influx.py", line 498, in post_request
return super(InfluxThread, self).post_request(request, payload)
File "/home/weewx/bin/weewx/restx.py", line 537, in post_request
_response = urllib.request.urlopen(request, data=data_bytes, timeout=self.timeout)
File "/usr/local/lib/python3.9/urllib/request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.9/urllib/request.py", line 523, in open
response = meth(req, response)
File "/usr/local/lib/python3.9/urllib/request.py", line 632, in http_response
response = self.parent.error(

File "/usr/local/lib/python3.9/urllib/request.py", line 561, in error

return self._call_chain(*args)
File "/usr/local/lib/python3.9/urllib/request.py", line 494, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.9/urllib/request.py", line 641, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/home/weewx/bin/weewx/restx.py", line 354, in run
self.run_loop(_manager)
File "/home/weewx/bin/weewx/restx.py", line 381, in run_loop
self.process_record(_record, dbmanager)
File "/home/weewx/bin/weewx/restx.py", line 446, in process_record
self.post_with_retries(_request, data)
File "/home/weewx/bin/weewx/restx.py", line 496, in post_with_retries
self.handle_exception(e, _count + 1)
File "/home/weewx/bin/user/influx.py", line 486, in handle_exception
if payload and payload.find("error") >= 0:

TypeError: argument should be integer or bytes-like object, not 'str'

You can workaround this by manually creating the db in influxdb, but you'll still get an error when it tries to create the db, but then it will successfully upload records:

Jan 1 22:39:08 weewx[17] INFO user.influx: service version is 0.15
Jan 1 22:39:08 weewx[17] INFO user.influx: database is weewx-docker
Jan 1 22:39:08 weewx[17] INFO user.influx: tags None
Jan 1 22:39:08 weewx[17] INFO user.influx: binding is loop,archive
Jan 1 22:39:08 weewx[17] ERROR user.influx: create database failed: HTTP Error 400: Bad Request

Jan 1 22:39:08 weewx[17] INFO user.influx: Data will be uploaded to http://influxdb.home:8086
Jan 1 22:39:08 weewx[17] INFO __main__: Starting up weewx version 4.2.0

Jan 1 22:39:08 weewx[17] INFO weewx.engine: Using binding 'wx_binding' to database 'weewx.sdb'
Jan 1 22:39:08 weewx[17] INFO weewx.manager: Starting backfill of daily summaries
Jan 1 22:39:08 weewx[17] INFO weewx.engine: Starting main packet loop.