前提・実現したいこと
プログラマーではないので、詳しくないのでご教授願いたいのですが、
さくらサーバーの領域にTera termにてpython3にて作られたgoogle hangout用のbot(https://github.com/hangoutsbot/hangoutsbot)をアップロードして、 hangupsbot.py ファイルを実行したのですが、
「auth.py」でのGoogle認証がうまくいきません(メールアドレスやパスワードは入力時間違ってないはずですが・・)、どのようにすればよろしいでしょうか?
発生している問題・エラーメッセージ
% python3 hangupsbot.py
17:31:07 INFO config: /home/●●●/.local/share/hangupsbot/config.json read
17:31:07 INFO root: memory = /home/●●●/.local/share/hangupsbot/memory.json, failsafe = 3, delay = 1
17:31:07 INFO config: /home/●●●/.local/share/hangupsbot/memory.json read
Sign in with your Google account:
Email: ●●●@gmail.com
Password:
17:32:50 ERROR root: LOGIN FAILED
Traceback (most recent call last):
File "/home/●●●/local/python/lib/python3.5/site-packages/hangups/auth.py", line 197, in get_auth
raise GoogleAuthError("Refresh token not found")
hangups.auth.GoogleAuthError: Refresh token not found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/●●●/local/python/lib/python3.5/site-packages/hangups/auth.py", line 340, in _get_authorization_code
return browser.get_cookie('oauth_code')
File "/home/●●●/local/python/lib/python3.5/site-packages/hangups/auth.py", line 298, in get_cookie
return self._session.cookies[name]
File "/home/●●●/local/python/lib/python3.5/site-packages/requests/cookies.py", line 328, in getitem
return self._find_no_duplicates(name)
File "/home/●●●/local/python/lib/python3.5/site-packages/requests/cookies.py", line 399, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='oauth_code', domain=None, path=None"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "hangupsbot.py", line 139, in login
cookies = hangups.auth.get_auth_stdin(cookies_path)
File "/home/●●●/local/python/lib/python3.5/site-packages/hangups/auth.py", line 233, in get_auth_stdin
CredentialsPrompt(), refresh_token_cache, manual_login=manual_login
File "/home/●●●/local/python/lib/python3.5/site-packages/hangups/auth.py", line 208, in get_auth
session, credentials_prompt
File "/home/●●●/local/python/lib/python3.5/site-packages/hangups/auth.py", line 342, in _get_authorization_code
raise GoogleAuthError('Authorization code cookie not found')
hangups.auth.GoogleAuthError: Authorization code cookie not found
17:32:50 ERROR root: Valid login required, exiting
###以下「auth.py」のテキスト(文字量制限のため途中まで)
"""Google login authentication using OAuth 2.0.
Logging into Hangouts using OAuth2 requires a private scope only whitelisted
for certain clients. This module uses the client ID and secret from iOS, so it
will appear to Google to be an iOS device. Access can be revoked from this
page:
https://security.google.com/settings/security/activity
This module should avoid logging any sensitive login information.
This module may be tested by invoking it directly:
python -m hangups.auth
"""
import getpass
import logging
import platform
import urllib.parse
import mechanicalsoup
import requests
from hangups import version
logger = logging.getLogger(name)
(# Set the logging level for requests to at least INFO, since the DEBUG level
(# will log sensitive data:
if logging.getLogger('requests').isEnabledFor(logging.DEBUG):
logging.getLogger('requests').setLevel(logging.INFO)
OAUTH2_CLIENT_ID = '●●●.apps.googleusercontent.com'
OAUTH2_CLIENT_SECRET = '●●●'
OAUTH2_SCOPES = [
'https://www.google.com/accounts/OAuthLogin',
'https://www.googleapis.com/auth/userinfo.email',
]
(# Note that '+' separating scopes must not be escaped by urlencode
OAUTH2_LOGIN_URL = (
'https://accounts.google.com/o/oauth2/programmatic_auth?{}'.format(
urllib.parse.urlencode(dict(
scope='+'.join(OAUTH2_SCOPES),
client_id=OAUTH2_CLIENT_ID,
), safe='+')
)
)
OAUTH2_TOKEN_REQUEST_URL = 'https://accounts.google.com/o/oauth2/token'
FORM_SELECTOR = '#gaia_loginform'
EMAIL_SELECTOR = '#Email'
PASSWORD_SELECTOR = '#Passwd'
VERIFICATION_FORM_SELECTOR = '#challenge'
TOTP_CHALLENGE_SELECTOR = '[action="/signin/challenge/totp/2"]'
PHONE_CHALLENGE_SELECTOR = '[action="/signin/challenge/ipp/4"]'
TOTP_CODE_SELECTOR = '#totpPin'
PHONE_CODE_SELECTOR = '#idvPreregisteredPhonePin'
USER_AGENT = 'hangups/{} ({} {})'.format(
version.version, platform.system(), platform.machine()
)
MANUAL_LOGIN_INSTRUCTIONS = '''
To sign in with your Google account:
1) Open the URL provided below in your browser. 2) Log into your Google account normally. 3) You should be redirected to a loading screen. Copy the `oauth_code` cookie value set by this page and paste it here.
To obtain the cookie value using Chrome or Firefox:
1) Press F12 to open developer tools. 2) Select the "Application" (Chrome) or "Storage" (Firefox) tab. 3) In the sidebar, expand "Cookies" and select `https://accounts.google.com`. 4) In the cookie list, double click on the value for the `oauth_code` cookie to select it, and copy the value.
{}
'''.format(OAUTH2_LOGIN_URL)
class GoogleAuthError(Exception):
"""A Google authentication request failed."""
###**エラーメッセージ** raise GoogleAuthError('Authorization code cookie not found') hangups.auth.GoogleAuthError: Authorization code cookie not found 17:32:50 ERROR root: Valid login required, exiting ### 該当のソースコード BotライブラリのGitHubページは↓ GitHub – hangoutsbot/hangoutsbot: Google Hangouts bot https://github.com/hangoutsbot/hangoutsbot ### 試したこと 「auth.py」のなかに OAUTH2_CLIENT_ID = '●●●.com' OAUTH2_CLIENT_SECRET = '●●●' OAUTH2_SCOPES = [ 'https://www.google.com/accounts/OAuthLogin', 'https://www.googleapis.com/auth/userinfo.email', OAUTH2_CLIENT_ID とOAUTH2_CLIENT_SECRET とあったので、 https://developer.a-blogcms.jp/document/externalservice/entry-2541.html を参考にしてそれと思われるものを直接テキストに書き込んだがうまくいかず ### 補足情報(FW/ツールのバージョンなど) auth.pyの中身がどうなっているのか、という話になるかと思います。 hangupsbotは以下を参考にしてインストールしました。 https://qiita.com/Shota_Fukuda/items/bd36c543ac6fbefb685e ただし、上記サイトの冒頭にある通り 「2018/08/20時点でGoogle側の認証方法が変わったのか、下記の方法で作成したBotは動きません。」 とあります。同じgit clone(というのでしょうか、データ参照元)で、Google側の認証方法変更以後(去年の6月頃?)も、環境は違えどbotを動かした人がいるようですので、動かす方法はあるんだと思うんですが、どうしていいかわかりません。 ↓ 1月20日 プログラミングに詳しい方が上記のbotを試してくださり、記述の方法(VS2017でのbot構築手順)では同じように認証エラーとなったが、回避方法が分かったとのこと。ただし教わった内容を自分の環境で試したところ、今までとは挙動が変わりましたが、エラーになり動きません。途中いろいろ内容をいじってしまったのでその影響かと思われます。トークン・クッキーの取得と認証、といったあたりで躓いていたようです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。