Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'SSLCertVerificationError' object is not iterable #162

Open
zamirTo1 opened this issue Oct 20, 2020 · 6 comments · May be fixed by #344
Open

TypeError: 'SSLCertVerificationError' object is not iterable #162

zamirTo1 opened this issue Oct 20, 2020 · 6 comments · May be fixed by #344

Comments

@zamirTo1
Copy link

Hey,
I'm running this command and getting:
github-backup $ORGANIZATION -P -t $ACCESS_TOKEN -o . --all -O -R $REPO

2020-10-20T15:42:30.277186: Backing up user XXXXXXX to /Users/Backup/
2020-10-20T15:42:30.277497: Requesting https://api.github.com/user?per_page=100&page=1
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1319, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1230, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1276, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1225, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1004, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 944, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1399, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/github_backup/github_backup.py", line 519, in _get_response
    r = urlopen(request)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1362, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1322, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/bin/github-backup", line 42, in <module>
    main()
  File "/Library/Frameworks/Python.framework/Versions/3.8/bin/github-backup", line 31, in main
    authenticated_user = get_authenticated_user(args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/github_backup/github_backup.py", line 654, in get_authenticated_user
    data = retrieve_data(args, template, single_request=True)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/github_backup/github_backup.py", line 502, in retrieve_data
    return list(retrieve_data_gen(args, template, query_args, single_request))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/github_backup/github_backup.py", line 457, in retrieve_data_gen
    r, errors = _get_response(request, auth, template)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/github_backup/github_backup.py", line 524, in _get_response
    log_warning(e.reason)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/github_backup/github_backup.py", line 86, in log_warning
    for msg in message:
TypeError: 'SSLCertVerificationError' object is not iterable
@bfoz
Copy link

bfoz commented Dec 4, 2020

Did you ever find a fix for this? I'm seeing the same problem now.

@zamirTo1
Copy link
Author

zamirTo1 commented Dec 5, 2020

Hey,
Yes, If you are using Python3, go to github_backup.py and add
import ssl
and overwrite _get_response function:

def _get_response(request, auth, template):
    retry_timeout = 3
    errors = []
    ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE
    # We'll make requests in a loop so we can
    # delay and retry in the case of rate-limiting
    while True:
        should_continue = False
        try:
            r = urlopen(request, context=ctx)
        except HTTPError as exc:
            errors, should_continue = _request_http_error(exc, auth, errors)  # noqa
            r = exc
        except URLError as e:
            log_warning(e.reason)
            should_continue = _request_url_error(template, retry_timeout)
            if not should_continue:
                raise
        except socket.error as e:
            log_warning(e.strerror)
            should_continue = _request_url_error(template, retry_timeout)
            if not should_continue:
                raise

        if should_continue:
            continue

        break
    return r, errors

@cole-seph-work
Copy link

Confirmed @zamirTo1 's fix works!

@josegonzalez
Copy link
Owner

Pull requests welcome.

@xloem
Copy link

xloem commented Sep 22, 2024

Looked into this and found the following:

  • the solution above has likely not been submitted because it disabled https security
  • people likely don't discover their system is not configured because the popular requests package that is usually used in python, itself uses the certifi package for all requests, which embeds a certificate chain within python without regarding to the operating system
  • hence a better solution would be to import certifi and pass cafile=certifi.where() rather than creating an insecure context

Ideally a warning would be displayed if this procedure is necessary.

xloem pushed a commit to xloem/python-github-backup that referenced this issue Sep 22, 2024
Some users are relying solely on the certifi package to provide their CA certs, as requests does this by default.

This patch detects this situation and emits a clear warning as well as importing certifi to work around the situation..

Fixes josegonzalez#162 .
@xloem xloem linked a pull request Sep 22, 2024 that will close this issue
@xloem
Copy link

xloem commented Sep 22, 2024

Found this discussion: psf/requests#2966

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants