在本地python3.4下跑无报错,在服务器上跑出现报错:
Traceback (most recent call last):
File "bayes.py", line 87, in <module>
spamTest()
File "bayes.py", line 57, in spamTest
wordList=textParse(open('/home/wangmengge/nbc/email/spam/%d.txt' % i).read())
File "/usr/local/lib/python3.5/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 64: invalid start byte
解决办法:
在打开文件时,强制转换文件的格式从utf-8到ISO-8859-1.
添加: encoding='ISO-8859-1'
即:将57行改成
wordList=textParse(open('/home/wangmengge/nbc/email/spam/%d.txt' % i,encoding='ISO-8859-1').read())