Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests to luftdaten should be in try except #79

Closed
wants to merge 1 commit into from

Conversation

ulrischa
Copy link

@ulrischa ulrischa commented Aug 5, 2020

Requests to luftdaten should be in try except block. If script runs in background and and network (e.g. DNS) error occured, the script stops running.

Requests to luftdaten should be in try except block. If script runs in background and and network (e.g. DNS) error occured, the script stops running.
@Gadgetoid
Copy link
Member

I must preface this with: I didn't write the luftdaten script, and I'm not familiar with their API beyond what I can glean from brushing up on the documentation.

While I agree in principle, a bare Except clause is an antipattern in Python- it should trap the specific network error and do something useful such as retry sending the data a limited number of times, just in case it's a temporary exception.

While a hard fail is pretty nasty, it's probably better than the script quietly failing indefinitely while squashing any useful debug output.

I can see a few improvements to this script that might go nicely with your proposal, not least of all:

  1. Moving update_time = time.time() to before send_to_luftdaten so the data sending function has the full 145??? seconds to retry sending the values. Though I can't see any fearture for sending a timestamp to luftdaten.
  2. Adding python logging, so we can log success/failure states and other info with timestamps, this is illustrated nicely here:
    import logging
    logging.basicConfig(
    format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
    level=logging.INFO,
    datefmt='%Y-%m-%d %H:%M:%S')
    logging.info("""all-in-one.py - Displays readings from all of Enviro plus' sensors
    Press Ctrl+C to exit!
    """)

I don't expect you to make all of these changes, but if you could at least update the try/catch to produce some useful debug output it would be a good start that I could merge and promote the rest of this to an Issue.

Thank you for taking the time to make a PR!

@ulrischa
Copy link
Author

ulrischa commented Aug 5, 2020 via email

@Gadgetoid
Copy link
Member

Well it's MIT code for an open data service, but I understand.

I can't merge a PR that exchanges one kind of broken for another, however, so I'll promote this to an issue and find time to give this example a proper once over.

Thanks again!

@ulrischa
Copy link
Author

ulrischa commented Aug 5, 2020 via email

@roscoe81 roscoe81 mentioned this pull request Aug 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants