Q:

datetime: conversion from string with timezone name not working

I have the following string "2017-03-30 08:25:00CET" which I want to convert to a datetime tz-aware object.
According this SO question, from python 3.2 it can be done using only datetime module. In addition, from the documentation, I see

%z |  UTC offset in the form +HHMM or -HHMM (empty string if the object is naive). |  (empty), +0000, -0400, +1030
%Z |  Time zone name (empty string if the object is naive).                        |  (empty), UTC, EST, CST

So I try the following
datetime.strptime(dep_dt, '%Y-%m-%d %H:%M:%S%Z')

I do not get any error, but then the object I get is not tz-aware
datetime.datetime(2017, 3, 30, 8, 25)

On the other hand, if I convert my string to "2017-03-30 08:25:00+0200" and then convert it to an object with 
datetime.strptime(dep_dt, '%Y-%m-%d %H:%M:%S%z')
I do get a tz-aware datetime:
datetime.datetime(2017, 3, 30, 8, 25, tzinfo=datetime.timezone(datetime.timedelta(0, 7200)))

Any ideas of why it works with %z but not with %Z? What am I doing wrong?

A:

Judging from the information given by tzinfo, the %Z does not work the way that you feed in a string like "UTC" and it will return a datetime instance with the correct timezone. 
pytz provides a possible solution to your problem. However, the documentation says, that there is no guarentee that your timezone will be recognized by datetime and recommends working with UTC as long as possible. 
Solution using pytz:
from datetime import datetime
from pytz import timezone
dep_dt = '2017-03-30 08:25:00CET'
dt = datetime.strptime(dep_dt, '%Y-%m-%d %H:%M:%S%Z')
timezone(dep_dt[19:]).localize(dt)

Out:
datetime.datetime(2017, 3, 30, 8, 25, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>)

