Change this line
filename1 = datetime.now().strftime("%Y%m%d-%H%M%S")
To
filename1 = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
Note the extra datetime
. Alternatively, change your
import datetime
to from datetime import datetime