datetime.strptime strange behavior

I'm getting the following error on aws virtual machine running python 3.6.8, while on my laptop it works fine with python 3.6.1

   return datetime.strptime(date_str, self.date_format)
  File "/usr/lib64/python3.6/", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib64/python3.6/", line 362, in _strptime
    (data_string, format))
ValueError: time data 'Fri, 23 Aug 2019 20:24:46 IDT' does not match format '%a, %d %b %Y %H:%M:%S %Z'

What's wrong with the format that I'm using?

Answers 1

  • See this discussion on the official Python bug tracker. Apparently %Z only supports UTC, GMT and the local time zone (as returned by time.tzname).

    It's an interesting case, the official Python docs are misleading (to put it nicely):

    %Z Time zone name (empty string if the object is naive).(empty), UTC, EST, CST

    This is wrong. %Z will only recognise EST, CST, etc. if they are the local timezone of the OS.

    EDIT Well, there is a note near the bottom of the page in the docs that says

    %Z If tzname() returns None, %Z is replaced by an empty string. Otherwise %Z is replaced by the returned value, which must be a string.

    Still, not as clear as it could be.

    To make it clear:

    It works on your local machine because it uses IDT as its local timezone, which is not the case for the AWS remote machine.

Related Articles