djjudas21 / ecowitt-exporter

EcoWitt exporter for Prometheus
4 stars 3 forks source link

werkzeug.exceptions.BadRequestKeyError #15

Closed pdostal closed 9 months ago

pdostal commented 9 months ago

Hello,

I just updated from 19f02f9 to 75e722d and am getting the following error:

Debug log:

[2023-12-26 07:03:55,967] DEBUG in ecowitt_exporter: Body: b'PASSKEY=XXX&stationtype=WN1920A_V1.1.4&runtime=9541294&dateutc=2023-12-26+07:03:55&tempinf=69.08&humidityin=54&baromrelin=27.714&baromabsin=27.714&tempf=42.80&humidity=89&winddir=80&windspeedmph=3.13&windgustmph=4.47&maxdailygust=9.17&uv=0&rainratein=0.000&eventrainin=0.000&hourlyrainin=0.000&dailyrainin=0.000&weeklyrainin=0.878&monthlyrainin=2.567&yearlyrainin=12.858&totalrainin=12.858&temp1f=80.06&humidity1=41&lightning_num=2&lightning=20&lightning_time=1703558439&console_batt=2.92&wh65batt=0&batt1=0&wh57batt=4&freq=868M&model=WN1920A'
[2023-12-26 07:03:55,967] DEBUG in ecowitt_exporter: Received raw value PASSKEY: XXX
[2023-12-26 07:03:55,968] DEBUG in ecowitt_exporter: Received raw value stationtype: WN1920A_V1.1.4
[2023-12-26 07:03:55,968] DEBUG in ecowitt_exporter: Received raw value runtime: 9541294
[2023-12-26 07:03:55,968] DEBUG in ecowitt_exporter: Received raw value dateutc: 2023-12-26 07:03:55
[2023-12-26 07:03:55,968] DEBUG in ecowitt_exporter: Received raw value tempinf: 69.08
[2023-12-26 07:03:55,969] DEBUG in ecowitt_exporter: Received raw value humidityin: 54
[2023-12-26 07:03:55,969] DEBUG in ecowitt_exporter: Received raw value baromrelin: 27.714
[2023-12-26 07:03:55,969] DEBUG in ecowitt_exporter: Received raw value baromabsin: 27.714
[2023-12-26 07:03:55,969] DEBUG in ecowitt_exporter: Received raw value tempf: 42.80
[2023-12-26 07:03:55,970] DEBUG in ecowitt_exporter: Received raw value humidity: 89
[2023-12-26 07:03:55,970] DEBUG in ecowitt_exporter: Received raw value winddir: 80
[2023-12-26 07:03:55,970] DEBUG in ecowitt_exporter: Received raw value windspeedmph: 3.13
[2023-12-26 07:03:55,970] DEBUG in ecowitt_exporter: Received raw value windgustmph: 4.47
[2023-12-26 07:03:55,971] DEBUG in ecowitt_exporter: Received raw value maxdailygust: 9.17
[2023-12-26 07:03:55,971] DEBUG in ecowitt_exporter: Received raw value uv: 0
[2023-12-26 07:03:55,971] DEBUG in ecowitt_exporter: Received raw value rainratein: 0.000
[2023-12-26 07:03:55,971] DEBUG in ecowitt_exporter: Received raw value eventrainin: 0.000
[2023-12-26 07:03:55,971] DEBUG in ecowitt_exporter: Received raw value hourlyrainin: 0.000
[2023-12-26 07:03:55,972] DEBUG in ecowitt_exporter: Received raw value dailyrainin: 0.000
[2023-12-26 07:03:55,972] DEBUG in ecowitt_exporter: Received raw value weeklyrainin: 0.878
[2023-12-26 07:03:55,972] DEBUG in ecowitt_exporter: Received raw value monthlyrainin: 2.567
[2023-12-26 07:03:55,972] DEBUG in ecowitt_exporter: Received raw value yearlyrainin: 12.858
[2023-12-26 07:03:55,973] DEBUG in ecowitt_exporter: Received raw value totalrainin: 12.858
[2023-12-26 07:03:55,973] DEBUG in ecowitt_exporter: Received raw value temp1f: 80.06
[2023-12-26 07:03:55,973] DEBUG in ecowitt_exporter: Received raw value humidity1: 41
[2023-12-26 07:03:55,973] DEBUG in ecowitt_exporter: Received raw value lightning_num: 2
[2023-12-26 07:03:55,973] DEBUG in ecowitt_exporter: Received raw value lightning: 20
[2023-12-26 07:03:55,974] DEBUG in ecowitt_exporter: Received raw value lightning_time: 1703558439
[2023-12-26 07:03:55,974] DEBUG in ecowitt_exporter: Received raw value console_batt: 2.92
[2023-12-26 07:03:55,974] DEBUG in ecowitt_exporter: Received raw value wh65batt: 0
[2023-12-26 07:03:55,974] DEBUG in ecowitt_exporter: Received raw value batt1: 0
[2023-12-26 07:03:55,974] DEBUG in ecowitt_exporter: Received raw value wh57batt: 4
[2023-12-26 07:03:55,975] DEBUG in ecowitt_exporter: Received raw value freq: 868M
[2023-12-26 07:03:55,975] DEBUG in ecowitt_exporter: Received raw value model: WN1920A
192.168.122.1 - - [26/Dec/2023 07:03:55] "POST /report HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2213, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/werkzeug/middleware/dispatcher.py", line 80, in __call__
    return app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2193, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "//ecowitt_exporter.py", line 252, in logecowitt
    if data['pm25_avg_24h_ch1']:
       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/werkzeug/datastructures/structures.py", line 192, in __getitem__
    raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'pm25_avg_24h_ch1'

If you have a clue how to solve this, please let me know :smile:

Happy holidays

djjudas21 commented 9 months ago

Thanks for reporting. Looks like this is because the code assumes everyone has the air quality sensor WH41. I'll fix this...

djjudas21 commented 9 months ago

Please can you try https://github.com/djjudas21/ecowitt-exporter/commit/dea51b3f4fb422976728d9e125debd1269c14089 and let me know if it fixes your problem. Then I can tag a new release :slightly_smiling_face:

pdostal commented 9 months ago

Very cool, it works now! Thank you