Try os.path.exists, and consider os.makedirs for the creation.
if not os.path.exists(directory):
There's also race condition - if the directory is created between the os.path.exists and the os.makedirs calls, the os.makedirs will fail with an OSError. Unfortunately, blanket-catching OSError and continuing is not foolproof, as it will ignore a failure to create the directory due to other factors, such as insufficient permissions, full disk, etc.
Try the following:
import os, errno
except OSError as e:
if e.errno != errno.EEXIST: