首页 > 解决方案 > f.write(r.text) 停止在 cron-job 中工作

问题描述

我在我的 rapsberry pi 上运行了一个非常基本的网站抓取工具。

r = get(url)
with open('filename.html', 'w') as f:
        f.write(r.text)

在终端中运行它可以按预期工作。但是通过 cron 作业运行它会出现以下错误(通过 mailx 找到)

f.write(r.text)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 67005: ordinal not in range(128)

通过终端使用时导致脚本工作的原因:

>python thescript.py

但它不起作用

30 9 * * * python /home/pi/thescript.py

标签: pythoncronraspberry-pi3

解决方案


推荐阅读