python - Formatting a non english string -


i have written function needs format string contains hebrew letters, script runs when using english letters. when using hebrew ones, gives me following error:

the error is:

error:  'ascii' codec can't encode characters in position 0-3: ordinal not in range(128) 

function code (the code under define line indented , not seen in code block):

def postwp(gametitle,gamecode):     print "postwp activated, title: %s" % gametitle     mail = smtplib.smtp('smtp.gmail.com',587)     mail.ehlo()     mail.starttls()     mail.login('email@gmail.com','emailpassword')     message = 'subject: {}\n\n{}'.format(gametitle, gamecode)     print "sending mail..."     mail.sendmail('email@gmail.com','destination@mail.com',message)     mail.close() 

basically, problem occurs @ 'subject: {}\n\n{}'.format(gametitle, gamecode)'.

i wondering how can fixed. in advance trying help! best regards, have great day!

def postwp(gametitle,gamecode):     # additional parameter checking     if not isinstance(gametitle, basestring):         print "gametitle type error"         return     if not isinstance(gamecode, basestring):         print "gamecode type error"         return     if isinstance(gametitle, unicode):         gametitle = gametitle.encode('utf8')     if isinstance(gamecode, unicode):         gamecode = gamecode.encode('utf8')      # following remains same     print "postwp activated, title: %s" % gametitle     mail = smtplib.smtp('smtp.gmail.com',587)     mail.ehlo()     mail.starttls()     mail.login('email@gmail.com','emailpassword')     message = 'subject: {}\n\n{}'.format(gametitle, gamecode)     print "sending mail..."     mail.sendmail('email@gmail.com','destination@mail.com',message)     mail.close() 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -