Gmail APIを使用してメールを送信するPythonスクリプトがあります。手動でスクリプトを実行すると、すべて正常に動作します。ただし、スクリプトはcronジョブを経て実行されると、スクリプトは次のエラーで失敗します。Gmail APIを使用しているときにエラーが発生しました
/usr/local/lib/python2.7/dist-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access /root/.credentials/sendEmail.json: No such file or directory warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
私は、Pythonスクリプトと同じフォルダにclient_secret.jsonファイルをしました。どんな提案も大歓迎です。
更新日
これに関するアップデート。私はルートのcrontabのpythonファイルへの呼び出しを追加します。何ここで興味深いのは、今のコードを表示し、私はそこに自分のアプリケーションに切り替えて、それを入力するように求められてる、Gmailを使用するには自分のアプリケーションを許可するためにクリックスルーするURLです
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
:これは、2つの新しいエラーが発生しました。
パーミッションの問題のようです。ファイルを移動したり、ルートとして実行しようとしましたか? – Artyer
同じディレクトリにいるだけでは不十分です。 –
こんにちは@Artyer - あなたはpythonファイルを意味しますか? crontabは次のようになります:21 20 * * * sudo python /home/pi/python_scripts/glasses_scrape/glasses.py> /home/pi/ipsender.log 2>&1 –