From 5bf24464b00257a9fa5f66047a2f7815c1e4f8fb Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 28 Oct 2021 10:25:22 -0500 Subject: [PATCH] Fix parse_datetime to parse API datetime string format with Python 3.6 The '%z' directive didn't accept 'Z' until Python 3.7 --- tweepy/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tweepy/utils.py b/tweepy/utils.py index f11bcd0..4aa1c70 100644 --- a/tweepy/utils.py +++ b/tweepy/utils.py @@ -12,5 +12,6 @@ def list_to_csv(item_list): def parse_datetime(datetime_string): return datetime.datetime.strptime( - datetime_string, "%Y-%m-%dT%H:%M:%S.%f%z" - ) + datetime_string, "%Y-%m-%dT%H:%M:%S.%fZ" + ).replace(tzinfo=datetime.timezone.utc) + # Use %z when support for Python 3.6 is dropped -- 2.25.1