'Python datetime. ValueError: unconverted data remains: +00

I'm trying to convert a data string that comes from a data set into a datetime object and I am getting the following error,

This error is quite different than others I saw on other questions like Python- strptime ValueError unconverted data remains: :00

import datetime

date_ = '2021-08-31 21:14:39.901557+00'
source_date = datetime.datetime.strptime(date_, '%Y-%m-%d %H:%M:%S.%f')

My error

ValueError: unconverted data remains: +00


Solution 1:[1]

as @Bakuriu mentioned this is invalid

date_ = '2021-08-31 21:14:39.901557+00'

To fix it you should add the remaining zeros and add a %z to the strptime

date_ = '2021-08-31 21:14:39.901557+0000'
source_date = datetime.datetime.strptime(date_, '%Y-%m-%d %H:%M:%S.%f%z')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Armandas Astrauskas