2017-06-05 60 views
0

我有一個通過Gmail api發送電子郵件的python腳本。手動運行腳本時,一切正常。然而,當腳本通過一個cronjob運行,該腳本將失敗,並出現以下錯誤:使用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文件。任何建議將不勝感激。

UPDATE

對此的更新。我將該調用添加到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,現在會顯示一個代碼,我問切換到我的應用程序,並在那裏輸入它。

+0

似乎是一個問題。你有沒有試過移動文件或以root身份運行它? – Artyer

+0

只是在相同的目錄是不夠的。 –

+0

Hi @Artyer - 你的意思是python文件嗎? crontab如下:21 20 * * * sudo python /home/pi/python_scripts/glasses_scrape/glasses.py> /home/pi/ipsender.log 2>&1 –

回答

0

我通過將調用添加到root的crontab中的python文件來解決問題。 Gmail提示我批准我的應用程序使用Gmail,然後腳本按預期工作。

相關問題