【发布时间】:2017-11-06 16:18:18
【问题描述】:
我有一个通过 Gmail api 发送电子邮件的 python 脚本。手动运行脚本时,一切正常。但是,当脚本通过 cronjob 运行时,脚本会失败并出现以下错误:
/usr/local/lib/python2.7/dist-packages/oauth2client/_helpers.py:255:用户警告:无法访问/root/.credentials/sendEmail.json:没有这样的文件或目录 warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
我的 client_secret.json 文件与 python 脚本位于同一文件夹中。任何建议将不胜感激。
更新
对此进行更新。我将调用添加到 root 的 crontab 中的 python 文件。这产生了 2 个新错误:
Failed to start a local webserver listening on either port 8080
or port 8090. Please check your firewall settings and locally
running programs that may be blocking or using those ports.
Falling back to --noauth_local_webserver and continuing with
authorization.
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.compose&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=611764062141-gccaftd5eh9ekk11nv4007uh7t2qlr09.apps.googleusercontent.com&access_type=offline
Enter verification code: Traceback (most recent call last):
File "/home/pi/python_scripts/glasses_scrape/glasses.py", line 174, in <module>
credentials = get_credentials()
File "/home/pi/python_scripts/glasses_scrape/glasses.py", line 165, in get_credentials
credentials = tools.run_flow(flow, store, flags)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/tools.py", line 240, in run_flow
code = input('Enter verification code: ').strip()
EOFError: EOF when reading a line
这里有趣的是授权我的应用程序使用 gmail 的 URL,现在显示一个代码,我被要求切换到我的应用程序并在其中输入。
【问题讨论】:
-
似乎是权限问题。您是否尝试过移动文件或以 root 身份运行它?
-
仅仅在同一个目录是不够的。
-
嗨@Artyer - 你是说python文件吗? crontab如下: 21 20 * * * sudo python /home/pi/python_scripts/glasses_scrape/glasses.py > /home/pi/ipsender.log 2>&1
-
@RichieClose 移动 JSON 文件。非root用户无法从
/root目录中读取任何内容, -
@Artyer - 移动 sendEmail.json 文件还是我的 client_secret.json 文件?