coddingtonbear / python-myfitnesspal

Access your meal tracking data stored in MyFitnessPal programatically
MIT License
794 stars 136 forks source link

Bypassing encryption request when working on Linux VM. #95

Closed Mccombkp closed 4 years ago

Mccombkp commented 4 years ago

Hello,

I am trying to run a notebook that spits out an automated email report via google cloud, but I run into a problem when using a Linux VM that I do not encounter locally.

The library ask me to set an encrypted password to be launched the first time I am running the notebook, which makes it unable to automate as the workflow involves another notebook calling the notebook with the MFP data in it.

Here is the error code that gets raised when I enter the wrong password. Hopefully, someone would know if it is possible to edit one of the files to bypass this all together. Or if they know any possible command that I can set after inputting the login information that enters the password for me.

Thank you.

Edit P.S: apologies for remaking this topic. I made it a month ago and deleted it based on poor explanation of the issue at hand, and was unaware that Git doesn't permadelete topic. (I am new to all this.)

Please enter password for encrypted keyring: ········
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/keyrings/alt/file.py in _unlock(self)
    132         try:
--> 133             ref_pw = self.get_password('keyring-setting', 'password reference')
    134             assert ref_pw == 'password reference value'

~/anaconda3/lib/python3.7/site-packages/keyrings/alt/file_base.py in get_password(self, service, username)
     75             # decrypted the password
---> 76             password = self.decrypt(password_encrypted).decode('utf-8')
     77         except (configparser.NoOptionError, configparser.NoSectionError):

~/anaconda3/lib/python3.7/site-packages/keyrings/alt/file.py in decrypt(self, password_encrypted)
    167         plaintext = cipher.decrypt(data['password_encrypted'])
--> 168         assert plaintext.startswith(self.pw_prefix)
    169         return plaintext[3:]

AssertionError: 

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-1-f8e18ca30bbc> in <module>
     27 
     28 KEYRING_SYSTEM = 'python-myfitnesspal://myfitnesspal-password'
---> 29 mfp.keyring_utils.store_password_in_keyring("myname", "mypassword")
     30 client = mfp.Client('myusername')
     31 

~/anaconda3/lib/python3.7/site-packages/myfitnesspal/keyring_utils.py in store_password_in_keyring(username, password)
     33         KEYRING_SYSTEM,
     34         username,
---> 35         password,
     36     )
     37 

~/anaconda3/lib/python3.7/site-packages/keyring/core.py in set_password(service_name, username, password)
     46     """Set password for the user in the specified service.
     47     """
---> 48     _keyring_backend.set_password(service_name, username, password)
     49 
     50 

~/anaconda3/lib/python3.7/site-packages/keyrings/alt/file_base.py in set_password(self, service, username, password)
     86 
     87         # encrypt the password
---> 88         password_encrypted = self.encrypt(password.encode('utf-8'))
     89         # encode with base64
     90         password_base64 = base64.encodestring(password_encrypted).decode()

~/anaconda3/lib/python3.7/site-packages/keyrings/alt/file.py in encrypt(self, password)
    148         from Crypto.Cipher import AES
    149         IV = get_random_bytes(AES.block_size)
--> 150         cipher = self._create_cipher(self.keyring_key, salt, IV)
    151         password_encrypted = cipher.encrypt(self.pw_prefix + password)
    152         # Serialize the salt, IV, and encrypted password in a secure format

~/anaconda3/lib/python3.7/site-packages/keyring/util/properties.py in __get__(self, obj, objtype)
     50         if obj is None:
     51             return self
---> 52         return self.fget(obj)

~/anaconda3/lib/python3.7/site-packages/keyrings/alt/file.py in keyring_key(self)
     90         # _unlock or _init_file will set the key or raise an exception
     91         if self._check_file():
---> 92             self._unlock()
     93         else:
     94             self._init_file()

~/anaconda3/lib/python3.7/site-packages/keyrings/alt/file.py in _unlock(self)
    135         except AssertionError:
    136             self._lock()
--> 137             raise ValueError("Incorrect Password")
    138 
    139     def _lock(self):

ValueError: Incorrect Password
coddingtonbear commented 4 years ago

The library isn't itself asking you to provide a password, your system's keychain is, and the reason it's doing that is because we've asked your keychain to give us one of your stored passwords.

For situations in which you'd rather provide the password directly, you can always provide the password directly to your script by providing a second argument (as is mentioned in the last paragraph of the "Authentication" section of the readme):

import myfitnesspal

client = myfitnesspal.Client('my_username', 'my_password')

Good luck!

Mccombkp commented 4 years ago

Thank you very much!

coddingtonbear commented 4 years ago

No problem! Feel free to reach out on the gitter channel, too, if you run into questions.