Add captcha support#446
Open
xolox wants to merge 3 commits into
Open
Conversation
In response to the following build failure: https://travis-ci.org/tdryer/hangups/builds/473486378
tdryer
requested changes
Jan 6, 2019
| try: | ||
| logger.info('Detected captcha, opening image in browser: %s', url) | ||
| webbrowser.open(url) | ||
| except Exception as e: |
Owner
There was a problem hiding this comment.
Looks like webbrowser.open will just return False if it can't open a browser.
| prompts the user to enter the captcha text. | ||
| """ | ||
| try: | ||
| logger.info('Detected captcha, opening image in browser: %s', url) |
Owner
There was a problem hiding this comment.
It might be better to print this instead of logging it, so the URL appears on the screen in case we can't open a browser.
| browser.submit_form(FORM_SELECTOR, {PASSWORD_SELECTOR: password}) | ||
|
|
||
| if browser.has_selector(CAPTCHA_SELECTOR): | ||
| for image in browser._page.soup.select('div.captcha-img img'): |
Owner
There was a problem hiding this comment.
Static analysis is complaining about this private attribute access. We could add a Browser.select method instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: As explained in #445 I integrated
hangupsin my chat-archive program a few months ago. Back then (August 2018)hangupsworked fine for me, but a few weeks ago the authentication started failing and try as I might I could not get it to work again 🙁.Disclaimer: Initially I had assumed I'd done something stupid when integrating hangups (even though it had worked before) but using
python -m hangups.authhelped to confirm that my authentication problems had nothing to do with the integration betweenhangupsand chat-archive.Analysis:
_get_authorization_code()and dumping the response HTML to a temporary file so I could see what was going on 😇.hangupsdidn't handle this response it failed to select the mandatory TOTP challenge and as a result the exceptionhangups.auth.GoogleAuthError: Authorization code cookie not foundwas raised.Resolution:
hangupsthat would at the very least inform the user via logging that authentication was failing due to missing captcha support.pdbsession convinced me that it wouldn't be that hard to actually add support for captcha images instead of just logging a message, because I didn't see another reasonable[1] way to gethangupsto successfully connect again.[1] When I say "reasonable" I'm thinking about the potential audience of my chat-archive program, whom I'm not comfortable asking to open a
pdbprompt or use the "Web Developer Tools" to extract a cookie from a browser session.Expectation management:
I expect that
hangupsis used in a lot of different contexts (CLI, GUI, headless?) and I guess thewebbrowser.open()call might be deemed inappropriate, however:The
webbrowser.open()call is located insideCredentialsPromptso that this behavior can easily be overridden by extending.The captcha image URL is logged so that the user can manually open it if the use of
webbrowser.open()doesn't work.AFAICT when the captcha challenge is presented there was formerly (before this pull request) no way for
hangupsto ever finish successfully, so in that sense backwards compatibility shouldn't be a concern.If there's problems with my current implementation that need to be resolved before this can be merged, feel free to let me know, because I'd love to see this get merged. While this new functionality is likely to be fragile, right now it's definitely an added value for me 🙂.