opulentfox-29 / protonmail-api-client

This is not an official python ProtonMail API client. it allows you to read, send and delete messages in protonmail, as well as render a ready-made template with embedded images.
GNU General Public License v3.0
20 stars 7 forks source link

Cannot finish login with proton.login #8

Closed antopiahk closed 6 months ago

antopiahk commented 6 months ago

I am using the code from the getting started documentation.

from protonmail import ProtonMail
import os
from dotenv import load_dotenv

load_dotenv()

PROTON_PASSWORD= os.getenv("PROTON_PASSWORD")

username = "...@domain"
password = PROTON_PASSWORD

proton = ProtonMail()
proton.login(username, password)

...

This is the output I get in the console:

login success
Traceback (most recent call last):
  File "C:\lorem\mail.py", line 13, in <module>
    proton.login(username, password)
  File ".venv\Lib\site-packages\protonmail\client.py", line 87, in login
    self._parse_info_after_login()
  File "C:\lorem\.venv\Lib\site-packages\protonmail\client.py", line 765, in _parse_info_after_login
    address = self.__addresses()['Addresses'][0]
              ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'Addresses'

Note that I get the green message "login success".

Thanks for any help.

EDIT: I believe I found the issue. If I'm not mistaken, its due to 2FA enabled on my account. image

antopiahk commented 6 months ago

I resolved this issue by completely turning off 2FA for my account. This includes also turning off the 2FA requirements for business accounts.

Hope this might help anyone else having this issue!

opulentfox-29 commented 6 months ago

Now you can use Two-Factor Authentication(2FA). Just repeat login and you will be asked for a 2FA code.

proton.login(username, password)
enter 2FA code:
>? 123456

Or if you have a function that receives a 2FA code, use it:

def some_function_for_get_2fa_code() -> int:
    code = 123456  # some logic
    return code

proton.login(username, password, getter_2fa_code=some_function_for_get_2fa_code)

Warning: only TOTP is supported, U2F/FIDO (like USB key) is unsupported.