Skip to content

Conversation

@jiasli
Copy link
Member

@jiasli jiasli commented Dec 30, 2021

Description

Fix #20215 (comment)

Python 3.6 doesn't recognize timezone %z as +00:00. It only recognizes +0000:

> docker run -it --rm python:3.6

>>> import datetime
>>> datetime.datetime.strptime('12/30/2021 07:53:52 +00:00', '%m/%d/%Y %H:%M:%S %z')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/local/lib/python3.6/_strptime.py", line 362, in _strptime
    (data_string, format))
ValueError: time data '12/30/2021 07:53:52 +00:00' does not match format '%m/%d/%Y %H:%M:%S %z'

>>> datetime.datetime.strptime('12/30/2021 07:53:52 +0000', '%m/%d/%Y %H:%M:%S %z')
datetime.datetime(2021, 12, 30, 7, 53, 52, tzinfo=datetime.timezone.utc)

which means az login --identity with managed identity in App Service container still doesn't work with DEB, RPM packages, etc.

https://docs.python.org/3/library/datetime.html#technical-detail

Changed in version 3.7: When the %z directive is provided to the strptime() method, the UTC offsets can have a colon as a separator between hours, minutes and seconds. For example, '+01:00:00' will be parsed as an offset of one hour. In addition, providing 'Z' is identical to '+00:00'.

There is indeed a test azure.cli.core.auth.tests.test_adal_authentication.TestUtil.test_normalize_expires_on to verify this:

assert _normalize_expires_on("11/05/2021 15:18:31 +00:00") == 1636125511
assert _normalize_expires_on('1636125511') == 1636125511

However, the test is not executed by CI for Python 3.6 due to azdev issue

@jiasli jiasli self-assigned this Dec 30, 2021
@jiasli jiasli added this to the Dec 2021 (2022-01-04) milestone Dec 30, 2021
@yonzhan
Copy link
Collaborator

yonzhan commented Dec 30, 2021

Core

@jiasli jiasli merged commit 2e0a42f into Azure:dev Dec 30, 2021
@jiasli jiasli deleted the managed-identity branch December 30, 2021 12:23
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.

4 participants