my code works properly in local machine:
from datetime import datetime
import pytz
def convert_time(timestamp):
formats = ['%a, %d %b %Y %H:%M:%S %Z',
'%a, %d %b %Y %H:%M:%S %z',
'%Y-%m-%dT%H:%M:%S.%fZ']
for fmt in formats:
try:
dt = datetime.strptime(timestamp, fmt)
break
except ValueError as v:
print(v)
pass
utc_dt = dt.astimezone(pytz.UTC)
return str(utc_dt.strftime('%Y-%m-%d %H:%M:%S'))
print(convert_time("Mon, 04 Dec 2023 06:13:24 EDT"))
this code is for converting my date format to UTC format. For Example this format will convert as i expected:
"Thu, 01 Nov 2018 16:50:27 EDT"
and the output will be:
2018-11-01 20:50:27
but when i run this code on my vps i got this error:
time data 'Thu, 01 Nov 2018 16:50:27 EDT' does not match format ...


I added
print()in code and it shows that%Zdoesn't parseEDTnorEST.So you have to add
%a, %d %b %Y %H:%M:%S EDT'Full code which I used to test it:
Result: