簡體   English   中英

使用Gmail API時引發錯誤

[英]Error thrown while using Gmail API

我有一個Python腳本,可以通過Gmail api發送電子郵件。 手動運行腳本時,一切正常。 但是,通過cronjob運行腳本時,腳本將失敗,並顯示以下錯誤:

/usr/local/lib/python2.7/dist-packages/oauth2client/_helpers.py:255:用戶警告:無法訪問/root/.credentials/sendEmail.json:無此類文件或目錄警告。警告(_MISSING_FILE_MESSAGE.format(文檔名稱))

我將client_secret.json文件與python腳本放在同一文件夾中。 任何建議將不勝感激。

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

這里有趣的是單擊該URL來授權我的應用程序使用gmail,現在顯示代碼,並且要求我切換到我的應用程序並在其中輸入。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM