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
15 stars 5 forks source link

Protonmail doesn't yet support Python 3.12 #5

Closed markmcwiggins closed 4 months ago

markmcwiggins commented 5 months ago

There's a line in the 3.11 code that uses

input.read(file)

instead of just

input(file)

opulentfox-29 commented 5 months ago

I don't understand which input.read(file) you are talking about, but on Python 3.12 the installation fails due to not all libraries being updated yet. The aiohttp library cannot be installed due to an error in the multidict library But using this answer, you can set the environment variable MULTIDICT_NO_EXTENSIONS=1 and then everything will work:

Windows:

$Env:MULTIDICT_NO_EXTENSIONS=1

Linux:

export MULTIDICT_NO_EXTENSIONS=1

Then everything is as usual:

  1. Installation:
    pip install protonmail-api-client
    playwright install webkit
  2. Use:

    from protonmail import ProtonMail
    
    username = "...@proton.me"
    password = "..."
    passphrase = '...'
    pk = 'privatekey.....asc'
    
    proton = ProtonMail()
    
    proton.login(username, password)
    proton.pgp_import(pk, passphrase=passphrase)
    
    messages = proton.get_messages()
    print(len(messages))
    
    # I got:
    # login success
    # _async_get_messages: 100%|██████████| 2/2 [00:00<00:00,  5.60it/s]
    # 172

    This works for me, but don't forget that that answer says that the MULTIDICT_NO_EXTENSIONS=1 parameter slows down the library by 20-50 times, although I don't know if this matters in this project. I recommend staying on version 3.11 until all other libraries are updated.

opulentfox-29 commented 4 months ago

Now all libraries are updated and everything works as normal. You no longer need to use the MULTIDICT_NO_EXTENSIONS=1 option to use Python 3.12 Just:

pip install protonmail-api-client