Closed rzamana closed 2 years ago
@costastf I got into this very recently, I wasn't able to login because AWS was not requiring the Captcha, and the lib was throwing some exceptions because of it! Let me see if I can reproduce again...
I would be more inclined to think that something went wrong time wise and not that the captcha would not be required. There is an issue with the current implementation (i think). The process happens as quickly as possible but the back end services used are many and of course are eventually consistent. What I think happens is that when you go to the web UI loading all the javascript and stuff takes enough time for all the back end to align and present you with the catcha. With the library, since everything happens as quickly as it can i think that some times not all underlying systems actually make it in time and you get no catcha, but no because it is not required but it is not setup yet. (again, that is what I think, i have thought about it for some time due to same issues as you describe, but of course this is a bit tricky to validate/fix) Thoughts?
So, this is my exception:
File "/Users/rafaelzamanakineippe/Public/no_captcha/app.py", line 45, in __init__
self.start()
File "/Users/rafaelzamanakineippe/Public/no_captcha/app.py", line 68, in start
seed = self.account.mfa.create_virtual_device()
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/awsapilib/console/console.py", line 723, in mfa
session = self._get_iam_session(self.email, self.password, self.region, self.mfa_serial)
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/awsapilib/console/console.py", line 544, in _get_iam_session
redirect_url = self._get_root_console_redirect(email, password, session, mfa_serial=mfa_serial)
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/awsapilib/console/console.py", line 501, in _get_root_console_redirect
response = self._resolve_account_type_response(email, session=session)
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/awsapilib/console/console.py", line 460, in _resolve_account_type_response
parameters = self._update_parameters_with_captcha(parameters, response)
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/awsapilib/console/console.py", line 428, in _update_parameters_with_captcha
parameters.update({'captcha_guess': self._solver.solve(captcha.url),
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/awsapilib/captcha/captcha.py", line 161, in solve
response = requests.get(url)
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/requests/sessions.py", line 528, in request
prep = self.prepare_request(req)
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/requests/sessions.py", line 456, in prepare_request
p.prepare(
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/requests/models.py", line 316, in prepare
self.prepare_url(url, params)
File "/Users/rafaelzamanakineippe/Public/no_captcha/.venv/lib/python3.9/site-packages/requests/models.py", line 390, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'None': No schema supplied. Perhaps you meant http://None?
I understand your thoughts, but in my case this happened because of the absence of captcha. When I tried to login into the account using Chrome, I logged into the account without the requirement of captcha (meaning, AWS didn't asked me to solve a captcha)
@costastf Fixed! Also regarding the issue you mentioned, I do get sometimes an error in the line:
if not all([success,
response.json().get('properties').get('RedirectTo') is not None]):
raise InvalidAuthentication(f'Unable to authenticate, response received was: {response.text} '
f'with status code: {response.status_code}')
Where there is no RedirectTo
information, this might happen because of the fast pace of the lib (like you mentioned, but the status_code is 200).... But I was not able to dive into it.
@costastf I was so focused about the _resolve_account_type_response
method (where all the problem happens), that I didn't consider to only solve for the rest!
Just FYI I'm having the exact same issue of not having to do captchas and getting Invalid URL 'None'.
Thanks!!
v2.3.1 released with the fix, thanks @rzamana !
Hey! This is very insteresting! What is the actual usage case when logging to the console there is no captcha required?