Skip to content

Exporter fails if API returns null for any field #3

@jdppettit

Description

@jdppettit

Hey there, just wanted to raise this issue I have started seeing:

2025-07-04 22:44:16,583 DEBUG API response: 200; {
  "api_version" : "V1.1.0-1.0.41",
  "time_stamp" : 1751669056,
  "data_time_stamp" : 1751669035,
  "max_age" : 604800,
  "firmware_default_version" : "7.02",
  "fields" : ["sensor_index","last_seen","name","humidity","temperature","pressure","pm2.5","pm10.0","pm2.5_10minute"],
  "data" : [
    [119509,1751668989,"Nothern Meadows",null,null,null,7.0,7.9,6.6]
  ]
}
Traceback (most recent call last):
  File "/app/purpleair_exporter.py", line 289, in <module>
    main()
  File "/app/purpleair_exporter.py", line 78, in main
    collect_metrics(sensor_ids, api_key)
  File "/app/purpleair_exporter.py", line 89, in collect_metrics
    transform_sensor_data(parsed_data)
  File "/app/purpleair_exporter.py", line 156, in transform_sensor_data
    stat.labels(sensor_id = sensor_id, label = sensor_label).set(data[key])
  File "/usr/local/lib/python3.11/site-packages/prometheus_client/metrics.py", line 396, in set
    self._value.set(float(value))
                    ^^^^^^^^^^^^
TypeError: float() argument must be a string or a real number, not 'NoneType'

Seems like three of the expected return fields are actually null and there isn't code to handle this.

I'd be happy to submit a PR to handle the null case, just wanted to check to see if this is something you still maintain before I do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions