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

incorrect passphrase error #12

Closed Bbalduzz closed 1 month ago

Bbalduzz commented 1 month ago

Hi, I'm having problems reading messages due to an error thrown by pgpy. This is my current code:

from protonmail import ProtonMail
import random
import uuid

proton_username = "MyProtonEmail@proton.me"
proton_password = "MyProtonPassword"
passphrase = "<12 words phrase separated by spaces>"

proton = ProtonMail()
try:
    proton.load_session("session.pickle", auto_save=True)
except:
    print("no session found, logging in")
    proton.login(proton_username, proton_password)
    private_key = "privatekey.MyProtonEmail@proton.me-ce0...1f.asc"
    proton.pgp_import(private_key, passphrase=passphrase)
    proton.save_session("session.pickle")

messages = proton.get_messages()
assert len(messages) > 0, "No messages found."
print(messages[0].sender.address)
message = proton.read_message(messages[0])
print(message.sender.address)
print(message.body)

But I keep getting this error:

  File "/Users/edoardo/Library/Python/3.11/lib/python/site-packages/protonmail/client.py", line 118, in read_message
    message.body = self.pgp.decrypt(message.body)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/edoardo/Library/Python/3.11/lib/python/site-packages/protonmail/pgp.py", line 53, in decrypt
    with pgp_private_key.unlock(passphrase) as key:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/Users/edoardo/Library/Python/3.11/lib/python/site-packages/pgpy/pgp.py", line 1811, in unlock
    sk._key.unprotect(passphrase)
  File "/Users/edoardo/Library/Python/3.11/lib/python/site-packages/pgpy/packet/packets.py", line 941, in unprotect
    self.keymaterial.decrypt_keyblob(passphrase)
  File "/Users/edoardo/Library/Python/3.11/lib/python/site-packages/pgpy/packet/fields.py", line 1559, in decrypt_keyblob
    kb = super(EdDSAPriv, self).decrypt_keyblob(passphrase)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/edoardo/Library/Python/3.11/lib/python/site-packages/pgpy/packet/fields.py", line 1264, in decrypt_keyblob
    raise PGPDecryptionError("Passphrase was incorrect!")
pgpy.errors.PGPDecryptionError: Passphrase was incorrect!

Maybe I'm doing something wrong, I got the phrase from here

Screenshot 2024-06-03 at 17 39 14

Is it correct? What am I doing wrong?

opulentfox-29 commented 1 month ago

hello, you enter recovery phrase but you need pgp passphrase from the Email encryption keys section, you create the passphrase when you click on the export private key button

image

image