Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to authenticate and get calendar events #392

Open
juanfrilla opened this issue Aug 1, 2022 · 0 comments · May be fixed by #399
Open

Unable to authenticate and get calendar events #392

juanfrilla opened this issue Aug 1, 2022 · 0 comments · May be fixed by #399

Comments

@juanfrilla
Copy link

juanfrilla commented Aug 1, 2022

The problem

Hello, I'm using this script in order to get my calendar events:

from datetime import datetime, timedelta
 
api = PyiCloudService('my_apple_id', 'my_password')
if api.requires_2sa:
    import click
    print("Two-step authentication required. Your trusted devices are:")

    devices = api.trusted_devices
    for i, device in enumerate(devices):
        print(
            "  %s: %s" % (i, device.get('deviceName',
            "SMS to %s" % device.get('phoneNumber')))
        )

    device = click.prompt('Which device would you like to use?', default=0)
    device = devices[device]
    if not api.send_verification_code(device):
        print("Failed to send verification code")
        sys.exit(1)

    code = click.prompt('Please enter validation code')
    if not api.validate_verification_code(device, code):
        print("Failed to verify verification code")
        sys.exit(1)

start_date = datetime.now()
end_date = start_date + timedelta(hours=2)
events = api.calendar.events(from_dt = start_date, to_dt = end_date)

print(events)
  1. I don't have an apple device, had one and with that id and password i'm working, so I'm using two step authentication in order to receive an SMS in my non apple phone.
  2. I receive my SMS and I introduce the code number well but then it says me Failed to verify verification code.
  3. When I run the script for the second time with the same apple'id and password it throws me the error logs attached in this description, not authenticated ( ref: Traceback/Error logs)
  4. Then I realized that my account is locked and api.requires_2sa is set to False, so I need to go to https://appleid.apple.com/ and change my apple id's password.
  5. Changed my apple id's password and api.requires_2sa is set to True again, run the script and it says me Failed to verify verification code once again.

My question are:

  1. do I need to have an apple device in order to do this and try with two step authentication? (I think two factor authentication is not working)
  2. Why api.requires_2sa is set to True the first time and when you fail is set to False ?

Environment

  • pyiCloud release with the issue (pip show pyicloud): 1.0.0
  • Last working pyiCloud release (if known):
  • Service causing this issue:
  • Python version (python -V): Python 3.9.6
  • Operating environment (project deps/Docker/Windows/etc.): I'm using WSL:
    Distributor ID: Debian
    Description: Debian GNU/Linux 9.13 (stretch)
    Release: 9.13
    Codename: stretch

Traceback/Error logs

Traceback (most recent call last):
  File "/home/juanfran/tucalendi_api_arch/app/app/integrations/apple/icloud.py", line 70, in <module>
    events = api.calendar.events(from_dt = start_date, to_dt = end_date)
  File "/home/juanfran/tucalendi_api_arch/venv/lib/python3.9/site-packages/pyicloud/services/calendar.py", line 64, in events
    self.refresh_client(from_dt, to_dt)
  File "/home/juanfran/tucalendi_api_arch/venv/lib/python3.9/site-packages/pyicloud/services/calendar.py", line 57, in refresh_client
    req = self.session.get(self._calendar_refresh_url, params=params)
  File "/home/juanfran/tucalendi_api_arch/venv/lib/python3.9/site-packages/requests/sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
  File "/home/juanfran/tucalendi_api_arch/venv/lib/python3.9/site-packages/pyicloud/base.py", line 131, in request
    return self.request(method, url, **kwargs)
  File "/home/juanfran/tucalendi_api_arch/venv/lib/python3.9/site-packages/pyicloud/base.py", line 133, in request
    self._raise_error(response.status_code, response.reason)
  File "/home/juanfran/tucalendi_api_arch/venv/lib/python3.9/site-packages/pyicloud/base.py", line 189, in _raise_error
    raise api_error
pyicloud.exceptions.PyiCloudAPIResponseException: Authentication required for Account. (421)

Checklist

  • [X ] I've looked informations into the README.
  • [ X] I've looked informations into the pyiCloud's code.
  • [ X] I've looked informations in Google.

Additional information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant