Traceback (most recent call last):
File "AutomationTool.py", line 2, in <module>
import MultiProcessController, RedisUtil, ADUtils, json, time
File "/var/www/html/ARB-Automation/MultiProcessController.py", line 2, in <module>
import AdTitleExtraction, ADUtils, AdwordsClient, RedisUtil, FinalURLRetrieval, ClusterStrategy, \
File "/var/www/html/ARB-Automation/AdTitleExtraction.py", line 2, in <module>
import Config, ADUtils, re, wordsegment as WS, queue, threading, time
File "/var/www/html/ARB-Automation/ADUtils.py", line 3, in <module>
import pymssql, pymysql, wordsegment as WS, gc
File "/usr/local/lib/python3.4/site-packages/wordsegment.py", line 49, in <module>
bigram_counts = parse_file(join(basepath, 'bigrams.txt'))
File "/usr/local/lib/python3.4/site-packages/wordsegment.py", line 45, in parse_file
return dict((word, float(number)) for word, number in lines)
File "/usr/local/lib/python3.4/site-packages/wordsegment.py", line 45, in <genexpr>
return dict((word, float(number)) for word, number in lines)
File "/usr/local/lib/python3.4/site-packages/wordsegment.py", line 44, in <genexpr>
lines = (line.split('\t') for line in fptr)
File "/usr/local/lib/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1286: ordinal not in range(128)
我正在尝试在我的python代码中使用wordsegment并使用python3.4.4并且它曾经在我的本地机器上工作。我部署在生产服务器上,我得到了这个错误,我不知道为什么会这样。 有人可以帮帮我吗?
答案 0 :(得分:1)
如果所有其他方法都失败,Python 3会尝试从区域设置中推断出正确的输入/输出字符集。据推测,生产服务器上的语言环境不是UTF-8语言环境,这就是Python错误的原因。
您可以使用PYTHONIOENCODING
环境变量强制执行某种编码;例如
PYTHONIOENCODING=UTF-8 python myprogram.py
或设置正确的UTF-8语言环境,例如C.UTF-8或en_US.UTF-8。