I want to use imaplib to search particular emails, which subjects contain Chinese. I got the error like this:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
so i use .encode to encode to 'UTF-8', and I got nothing. The print print out is
0
[]
The right answer should be 71, which I search on my inbox through my mail. This is my code:
import imaplib,email
host = 'imap.263.net'
user = '***@***'
psw = '*****'
count = 0
con = imaplib.IMAP4(host,143)
con.login(user,psw)
con.select('INBOX',readonly =True)
eva = '日报'
# eva = eva.encode('utf-8')
resp,liujf = con.search('UTF-8','SUBJECT','%s'%eva, 'Since','01-Feb-2018')
items = liujf[0].split()
print(len(items))
print(items)
I guess it should be unicode problem. How can I fix it?