尝试创建一个 Twitter 机器人来读取行并发布它们。通过我的共享服务器空间上的 virtualenv 使用 Python3 和 tweepy。这是代码中似乎有问题的部分:
#!/foo/env/bin/python3
import re
import tweepy, time, sys
argfile = str(sys.argv[1])
filename=open(argfile, 'r')
f=filename.readlines()
filename.close()
这是我得到的错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 0: ordinal not in range(128)
该错误特别指向 f=filename.readlines()
作为错误来源。知道可能出什么问题了吗?谢谢。
原文由 r_e_cur 发布,翻译遵循 CC BY-SA 4.0 许可协议
我认为最好的答案(在 Python 3 中)是使用
errors=
参数:证明:
请注意,
errors=
可以是replace
或ignore
。这是ignore
的样子: