You can also do this in one line using gdal.Info as so:
epsg = int(gdal.Info(input, format='json')['coordinateSystem']['wkt'].rsplit('"EPSG","', 1)[-1].split('"')[0])
This does essentially the same thing as the answer provided by Lennert (which is also a legit way of getting the EPSG; not really a workaround). It reads the WKT representation of the file's spatial reference, then parses the string to extract the EPSG.
Note that this method is slightly more robust because gdal.Info is very flexible with the types of inputs it can take. input
may be a datasource, valid filepath, or anything within gdal's extensive virtual file systems, which allows this method to accommodate a large number of potential use cases.