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

get_local_time doesn't properly check the http response status code before attempting to parse the time #57

Closed
theacodes opened this issue Nov 27, 2019 · 3 comments
Labels
good first issue Good for newcomers

Comments

@theacodes
Copy link
Member

response = requests.get(api_url)

If the request is an error, such as 404 for User not found (example url), then this code will attempt to parse the response into a datetime anyway.

It should makes sure the status code is 200 before attempting to parse. If it's not, it should throw an exception and include the response text in the exception to help with debugging. As it stands, this will raise a very unhelpful error:

Traceback (most recent call last):
  File "code.py", line 44, in <module>
  File "adafruit_pyportal.py", line 629, in get_local_time
  File "adafruit_pyportal.py", line 625, in get_local_time
ValueError: invalid syntax for integer with base 10 

This would be an excellent first-time issue for someone.

@theacodes theacodes changed the title get_local_time doesn't properly check the http response status code before attempting to parse the time get_local_time doesn't properly check the http response status code before attempting to parse the time Nov 27, 2019
@ladyada ladyada added the good first issue Good for newcomers label Nov 27, 2019
@ladyada
Copy link
Member

ladyada commented Nov 27, 2019

good idea - thanks for spotting this one @theacodes
@brentru might also be a good one for you :)

@brentru
Copy link
Member

brentru commented Nov 27, 2019

@ladyada I'll leave it for a new contributor within the next 15 days as people's holiday purchases roll in. I'll patch/release by then if it doesn't get picked up.

@brentru
Copy link
Member

brentru commented Jan 28, 2020

Addressed in #63.

Merged into master and released in v3.1.8.

@brentru brentru closed this as completed Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants