Skip to content

Conversation

@lmazuel
Copy link
Member

@lmazuel lmazuel commented May 6, 2020

Fix #192

Code inspired from the one I wrote for azure-core

@lmazuel lmazuel requested a review from johanste May 6, 2020 23:58
@lmazuel
Copy link
Member Author

lmazuel commented May 7, 2020

Without the PR, trying to deserialize in a french VM:

>>> from msrest.serialization import Deserializer
>>> Deserializer.deserialize_rfc("Mon, 20 Nov 1995 19:12:08 -0500")
Traceback (most recent call last):
  File "/home/lmazuel/rfctest/lib/python3.6/site-packages/msrest/serialization.py", line 1818, in deserialize_rfc
    attr, "%a, %d %b %Y %H:%M:%S %Z")
  File "/usr/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib/python3.6/_strptime.py", line 362, in _strptime
    (data_string, format))
ValueError: time data 'Mon, 20 Nov 1995 19:12:08 -0500' does not match format '%a, %d %b %Y %H:%M:%S %Z'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lmazuel/rfctest/lib/python3.6/site-packages/msrest/serialization.py", line 1823, in deserialize_rfc
    raise_with_traceback(DeserializationError, msg, err)
  File "/home/lmazuel/rfctest/lib/python3.6/site-packages/msrest/exceptions.py", line 51, in raise_with_traceback
    raise error.with_traceback(exc_traceback)
  File "/home/lmazuel/rfctest/lib/python3.6/site-packages/msrest/serialization.py", line 1818, in deserialize_rfc
    attr, "%a, %d %b %Y %H:%M:%S %Z")
  File "/usr/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib/python3.6/_strptime.py", line 362, in _strptime
    (data_string, format))
msrest.exceptions.DeserializationError: Cannot deserialize to rfc datetime object., ValueError: time data 'Mon, 20 Nov 1995 19:12:08 -0500' does not match format '%a, %d %b %Y %H:%M:%S %Z'

With the PR:

>>> from msrest.serialization import Deserializer
>>> Deserializer.deserialize_rfc("Mon, 20 Nov 1995 19:12:08 -0500")
datetime.datetime(1995, 11, 20, 19, 12, 8, tzinfo=<FixedOffset -5.0>)

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.

Parsing RFC date assumes current local is English

2 participants