You need to specify an encoding for the characters otherwise python doesn't know how to handle the strings.
import random import string random.choice(string.ascii_lowercase)