Closed lmazuel closed 4 years ago
Suggestion based on email stdlib
class _FixedOffset(datetime.tzinfo):
"""Fixed offset in minutes east from UTC.
Copy/pasted from Python doc
:param int offset: offset in minutes
"""
def __init__(self, offset):
self.__offset = datetime.timedelta(minutes=offset)
def utcoffset(self, dt):
return self.__offset
def tzname(self, dt):
return str(self.__offset.total_seconds()/3600)
def __repr__(self):
return "<FixedOffset {}>".format(self.tzname(None))
def dst(self, dt):
return datetime.timedelta(0)
def _parse_http_date(text):
parsed_date = email.utils.parsedate_tz(text)
return datetime.datetime(
*parsed_date[:6],
tzinfo=_FixedOffset(parsed_date[9]/60)
)
See azure-core polling for details
I encountered this problem and had to add specific workarounds to prevent it from crashing our program that uses azure-store-blob
.
Are there any plans to fix this soon?
Hey @Guts I wasn't sure if there was any impacted people yet, no I see your message I'm adding that in my TODO, thanks
@Guts would you have a stacktrace of the error available? Just for the sake of having this issue with all details.
@lmazuel do you still need the full trace? I've seen that you managed to reproduce in https://github.com/Azure/msrest-for-python/pull/201#issuecomment-624959102 ?
I just wanted to be sure I was addressing your problem, comparing the stackstrace would have made sure of it. But I think I got it, thanks! At least, if that sounds off to you let me know.
Example, trying to parse
Fri, 28 Feb 2020 19:04:06 GMT
with a spanish locale will fail, since "Fri" or "Feb" is not spanish. This is because this parser usesstrptime
which is local dependent. Python doesn't support configuration for locale.The only reliable way would be to stop using "strptime", since other solution like this relies on a thread lock and I don't like that.