kiwiz / gkeepapi

An unofficial client for the Google Keep API.
MIT License
1.52k stars 112 forks source link

`urllib3.util.ssl_ has no attribute DEFAULT_CIPHERS` #142

Closed danjenson closed 7 months ago

danjenson commented 1 year ago

Please make sure you've done the following before submitting your issue:

Additionally, please provide the following information:

#!/usr/bin/env python3
import argparse
import sys
from pathlib import Path

import gkeepapi
import keyring
import yaml

def main(args):
    keep = gkeepapi.Keep()
    with open(Path(args.credentials_path).expanduser()) as f:
        d = yaml.safe_load(f)
    keep.login(d["username"], d["password"])

def parse_args(argv):
    parser = argparse.ArgumentParser(
        prog=argv[0],
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    parser.add_argument('-c', '--credentials_path', default='~/.keys/google.yaml')
    return parser.parse_args(argv[1:])

if __name__ == "__main__":
    args = parse_args(sys.argv)
    main(args)

Stack trace:

λ python keep.py
Traceback (most recent call last):
  File "/data/scratch/keep.py", line 28, in <module>
    main(args)
  File "/data/scratch/keep.py", line 15, in main
    keep.login(d["username"], d["password"])
  File "/home/danj/.local/lib/python3.11/site-packages/gkeepapi/__init__.py", line 697, in login
    ret = auth.login(email, password, device_id)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/danj/.local/lib/python3.11/site-packages/gkeepapi/__init__.py", line 54, in login
    res = gpsoauth.perform_master_login(self._email, password, self._device_id)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/danj/.local/lib/python3.11/site-packages/gpsoauth/__init__.py", line 143, in perform_master_login
    return _perform_auth_request(data, proxy)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/danj/.local/lib/python3.11/site-packages/gpsoauth/__init__.py", line 78, in _perform_auth_request
    session.mount(AUTH_URL, AuthHTTPAdapter())
                            ^^^^^^^^^^^^^^^^^
  File "/home/danj/.local/lib/python3.11/site-packages/requests/adapters.py", line 155, in __init__
    self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)
  File "/home/danj/.local/lib/python3.11/site-packages/gpsoauth/__init__.py", line 68, in init_poolmanager
    context.set_ciphers(ssl_.DEFAULT_CIPHERS)
                        ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'urllib3.util.ssl_' has no attribute 'DEFAULT_CIPHERS'

It looks like urllib3 no longer defines this, which is used by gpsoauth. Unclear what the cleanest way to repair / mediate this going forward is, as it seems we need to specify a cipher in order for google to permit logins. I manually modified the gpsoauth package to put the DEFAULT_CIPHERS back in but still got (BadAuthentication, None) error.

abeisleem commented 1 year ago

Reverting to the following library to an older version helped for me: pip3 install requests==2.23.0 It's certainly not a ideal solution but it may fit your needs.

danjenson commented 1 year ago

Thanks! Although, I think it is important to properly set the cipher or have a reasonable default going forward, and I'm not sure what makes the most sense for this library/API.

listerr commented 1 year ago

I encountered the same error (urllib3.util.ssl_ has no attribute DEFAULT_CIPHERS).

Tried this and also downgrading urllib to 1.25.11 as suggested elsewhere, but now I get:

robl@:~/venv_test$ ./foo.py
Traceback (most recent call last):
  File "/home/robl/venv_test/./foo.py", line 8, in <module>
    success = keep.login('username', 'XXXX')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/robl/venv_test/lib/python3.11/site-packages/gkeepapi/__init__.py", line 697, in login
    ret = auth.login(email, password, device_id)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/robl/venv_test/lib/python3.11/site-packages/gkeepapi/__init__.py", line 62, in login
    raise exception.LoginException(res.get("Error"), res.get("ErrorDetail"))
gkeepapi.exception.LoginException: ('BadAuthentication', None)
robl@:~/venv_test$ ./bin/pip list
Package            Version
------------------ --------
certifi            2023.5.7
cffi               1.15.1
chardet            3.0.4
charset-normalizer 3.1.0
cryptography       41.0.1
future             0.18.3
gkeepapi           0.14.2
gpapi              0.4.4
gpsoauth           1.0.2
idna               2.10
pip                23.0.1
protobuf           4.23.3
pycparser          2.21
pycryptodomex      3.18.0
requests           2.23.0
setuptools         66.1.1
urllib3            1.25.11

Any hints?

jdegregorio commented 1 year ago

I'm experiencing the same issue.

jkitching commented 1 year ago

The DEFAULT_CIPHERS issue looks like it has been fixed here: https://github.com/simon-weber/gpsoauth/issues/52

For those of you who have downgraded to urllib3==1.26.16 and are getting BadAuthentication errors, that is a separate issue: https://github.com/simon-weber/gpsoauth/issues/48

openssl3 doesn't work... so I wrote a small Dockerfile to take care of getting a master token. After you have a master token, you can use other functionality with openssl3 without worrying about the BadAuthentication error. https://github.com/simon-weber/gpsoauth/issues/48#issuecomment-1690340572

kiwiz commented 7 months ago

Closing since the issue is now resolved.