gpt4 book ai didi

python - Unicode解码错误: 'ascii' codec can't decode byte 0xc3 in position 1286: ordinal not in range(128)

转载 作者:太空宇宙 更新时间:2023-11-03 16:49:22 48 4
gpt4 key购买 nike

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,它曾经在我的本地计算机上工作。我部署在生产服务器上并收到此错误,我不知道为什么会发生这种情况。有人可以帮我吗?

最佳答案

如果其他方法都失败,Python 3 会尝试从区域设置中推导出正确的输入/输出字符集。大概您的生产服务器上的区域设置不是 UTF-8 区域设置,这就是 Python 出错的原因。

您可以使用PYTHONIOENCODING环境变量强制某种编码;例如

PYTHONIOENCODING=UTF-8 python myprogram.py

或者通过设置正确的 UTF-8 区域设置,例如 C.UTF-8 或 en_US.UTF-8。

关于python - Unicode解码错误: 'ascii' codec can't decode byte 0xc3 in position 1286: ordinal not in range(128),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36011889/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com