Skip to content

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

Closed
@theacodes

Description

@theacodes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions