Fix parse_datetime to parse API datetime string format with Python 3.6
authorHarmon <Harmon758@gmail.com>
Thu, 28 Oct 2021 15:25:22 +0000 (10:25 -0500)
committerHarmon <Harmon758@gmail.com>
Thu, 28 Oct 2021 15:26:55 +0000 (10:26 -0500)
The '%z' directive didn't accept 'Z' until Python 3.7

tweepy/utils.py

index f11bcd006a97c64e37ac6351bd634d08886dad26..4aa1c70a0514577898392c288fb58df262162489 100644 (file)
@@ -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