Skip to content

Don't call API if no API key is available #63

Description

@sjjh

I suggest, that if a user does not alter the env-file-parameters, no call to the API should be made.

My /etc/led_mon/led_mon.env:

#API keys for IP adderss and weather lookup

# Get a free API key from https://iplocate.io
IP_LOCATE_API_KEY=YOUR_API_KEY

# Get a free API key from https://openweathermap.org/api
OPENWEATHER_API_KEY=c4f05d292e7a496d6831c78a6f89ad05

LOG_LEVEL=debug

Log output:

Aug 24 17:14:53 host led_mon[46558]: 2026-08-24 17:14:53,953 DEBUG urllib3.connectionpool: Starting new HTTPS connection (1): api.ipify.org:443
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,648 DEBUG urllib3.connectionpool: https://api.ipify.org:443 "GET / HTTP/1.1" 200 14
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,652 DEBUG httpcore.connection: connect_tcp.started host='iplocate.io' port=443 local_address=None timeout=30.0 socket_options=None
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,797 DEBUG httpcore.connection: connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x762032ed4eb0>
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,797 DEBUG httpcore.connection: start_tls.started ssl_context=<ssl.SSLContext object at 0x762032e42bd0> server_hostname='iplocate.io' timeout=30.0
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,950 DEBUG httpcore.connection: start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x762032ed4f00>
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,950 DEBUG httpcore.http11: send_request_headers.started request=<Request [b'GET']>
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,950 DEBUG httpcore.http11: send_request_headers.complete
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,950 DEBUG httpcore.http11: send_request_body.started request=<Request [b'GET']>
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,950 DEBUG httpcore.http11: send_request_body.complete
Aug 24 17:14:54 host led_mon[46558]: 2026-08-24 17:14:54,950 DEBUG httpcore.http11: receive_response_headers.started request=<Request [b'GET']>
Aug 24 17:14:55 host led_mon[46558]: 2026-08-24 17:14:55,131 DEBUG httpcore.http11: receive_response_headers.complete return_value=(b'HTTP/1.1', 401, b'Unauthorized', [(b'Date', b'Mon, 24 Aug 2026 15:14:55 GMT'>
Aug 24 17:14:55 host led_mon[46558]: 2026-08-24 17:14:55,131 INFO httpx: HTTP Request: GET https://iplocate.io/api/lookup/1.2.3.4?apikey=YOUR_API_KEY "HTTP/1.1 401 Unauthorized"
Aug 24 17:14:55 host led_mon[46558]: 2026-08-24 17:14:55,131 DEBUG httpcore.http11: receive_response_body.started request=<Request [b'GET']>
Aug 24 17:14:55 host led_mon[46558]: 2026-08-24 17:14:55,131 DEBUG httpcore.http11: receive_response_body.complete
Aug 24 17:14:55 host led_mon[46558]: 2026-08-24 17:14:55,131 DEBUG httpcore.http11: response_closed.started
Aug 24 17:14:55 host led_mon[46558]: 2026-08-24 17:14:55,131 DEBUG httpcore.http11: response_closed.complete
Aug 24 17:14:55 host led_mon[46558]: 2026-08-24 17:14:55,131 ERROR time_weather: Error getting weather: IPLocate API error (401): Invalid API key

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions