在OS X El Capitan上通过crontab启动python脚本

问题描述 投票:0回答:1

我有一个工作的python3脚本,我已经通过crontab -e设置了crontab。我添加了这一行

* * * * *  /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 /Users/harvey/PycharmProjects/3_5_pgm/3woerter.py

cron正在执行脚本,但我收到一封包含此错误消息的电子邮件:

X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=harvey>
X-Cron-Env: <USER=harvey>
X-Cron-Env: <HOME=/Users/harvey>
Message-Id: <[email protected]>
Date: Wed, 21 Dec 2016 17:10:03 +0100 (CET)
Traceback (most recent call last):
  File "/Users/harvey/PycharmProjects/3_5_pgm/3woerter.py", line 43, in <module>
    website("http://www.krone.at/nachrichten/rss.html")
  File "/Users/harvey/PycharmProjects/3_5_pgm/3woerter.py", line 25, in website
    fobj_out.write(str(titleSoup))           # <--- in Ausgabedatei schreiben
UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 121: ordinal not in range(128)

所以我认为cron使用的是python2而不是python3当我尝试直接通过终端命令时,一切正常。

我如何确保cron正在使用python3?

python macos cron
1个回答
0
投票

我也碰到了这个!我通过添加LC_ALLLANG解决了这个问题: LC_ALL=en_US.UTF-8 LANG=en_US.utf-8 * * * * * /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 /Users/harvey/PycharmProjects/3_5_pgm/3woerter.py

我之前学到了如何阅读http://click.pocoo.org/5/python3/#python-3-surrogate-handling的另一个问题

© www.soinside.com 2019 - 2024. All rights reserved.