Python3 IMAP搜索特殊字符 [英] Python3 IMAP search special characters
本文介绍了Python3 IMAP搜索特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Python3及其IMAP扩展程序在IMAP上找到注释。我尝试搜索包含特殊字符的主题,如以下示例所示。有没有一种方法可以将搜索字符串编码为与IMAP兼容?
I would like to find a note over IMAP using Python3 and it's IMAP extension. I try to search for a subject which contains special chars as in the example below. Is there a way I can encode the search string to be IMAP compatible?
self.connection.search(None, 'ALL', 'SUBJECT "büro"')
返回
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 10: ordinal not in range(128)
推荐答案
您应该传递UTF-8编码的字符串作为搜索参数,还需要提及 CHARSET UTF-8
You should pass UTF-8 encoded string as the search argument and also need to mention "CHARSET UTF-8" in the search query.
类似UID SEARCH CHARSET utf-8这样的东西搜索字符串。这里的搜索字符串应该是utf-8编码。
some thing like this UID SEARCH CHARSET utf-8 "search string". Here "search string" should be utf-8 encoded.
这篇关于Python3 IMAP搜索特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文