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

Incompatible ISO8601 format returned by the API #226

Closed
jooola opened this issue Jun 29, 2023 · 1 comment · Fixed by #228, #229, #231 or #233
Closed

Incompatible ISO8601 format returned by the API #226

jooola opened this issue Jun 29, 2023 · 1 comment · Fixed by #228, #229, #231 or #233
Assignees

Comments

@jooola
Copy link
Member

jooola commented Jun 29, 2023

Bug Report

Current Behavior

The floating IP API documentation is using the following ISO8601 format: 2016-01-30T23:55:00+00:00, but the API currently returns a different ISO8601 format: 2023-06-29T15:37:22Z.

We recently removed the python-dateutil package because we assumed the API will return the format in the documentation (without the Z), and use datetime.datetime.fromisoformat to parse the datetime.

Python <3.11 does not support parsing the 2023-06-29T15:37:22Z ISO8601 format, and this breaks our client for all version of Python <3.11.

Input Code

  • REPL or Repo link if applicable:

On python 3.9

>>> from datetime import datetime
>>> datetime.fromisoformat("2023-06-29T15:37:22Z")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid isoformat string: '2023-06-29T15:37:22Z'
>>> datetime.fromisoformat("2016-01-30T23:55:00+00:00")
datetime.datetime(2016, 1, 30, 23, 55, tzinfo=datetime.timezone.utc)

Expected behavior/code

The client should be able to parse the ISO8601 format.

Environment

  • Python Version: Python 3.9
  • Hcloud-Python Version: c821dbe

Possible Solution

Additional context/Screenshots

@jooola jooola self-assigned this Jun 29, 2023
@jooola jooola changed the title Invalid ISO8601 format returned by the API Incompatible ISO8601 format returned by the API Jun 30, 2023
jooola added a commit to jooola/hcloud-python that referenced this issue Jun 30, 2023
jooola added a commit that referenced this issue Jun 30, 2023
* fix: handle Z timezone in ISO8601 datetime format

Fixes #226
@jooola
Copy link
Member Author

jooola commented Jun 30, 2023

The API is also returning ISO8601 datetime with microseconds precision, some of those microseconds precision (depending on the precision) aren't parsable by fromisoformat for python < 3.11.

Example:
2023-06-30T15:09:46.37719+00:00

>>> from datetime import datetime, timezone
>>> datetime.fromisoformat('2023-06-30T15:09:46.37719+00:00')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid isoformat string: '2023-06-30T15:09:46.37719+00:00'
>>> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment