1. 程式人生 > >python+pandas+openpyxl下載xls illegalCharacterError

python+pandas+openpyxl下載xls illegalCharacterError

not 下載 去掉 mark http edi url sub set

僅僅是urllib2.unquote_plus解碼是不夠的,需要將特殊字符去掉

ILLEGAL_CHARACTERS_RE = re.compile(r‘[\000-\010]|[\013-\014]|[\016-\037]|\xef|\xbf‘)
value = ILLEGAL_CHARACTERS_RE.sub(‘‘, origin_value)
由於\xef|\xbf的存在,導致字符串亂碼,查了一下這是作為utf-8 BOM的存在,需要過濾掉。

BOM: https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8

ASCII Characters: http://donsnotes.com/tech/charsets/ascii.html

Then, it worked for me.

python+pandas+openpyxl下載xls illegalCharacterError