ntalekt / Cox_Data_Usage

Script that collects Cox Communications data usage for internet subscribers
18 stars 8 forks source link

SSL certificate verification failed #2

Closed hhcalder92 closed 5 years ago

hhcalder92 commented 6 years ago

Hello,

Firstly, thanks for sharing this script!

I just noticed that it stopped working within the last few weeks.

Looks like the login action is to POST on https://idm.east.cox.net/idm/coxnetlogin, which has a valid certificate. Was this how it was designed during your implementation?

During the manual login, via Firebug, I noticed the SmMakeCookie request(same request as below) is taking longer than most request. Unfortunately, increasing the timeout didnt help.

Is this broken for anyone else?

$ python3 /usr/local/bin/cox_usage.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 356, in connect
    ssl_context=context)
  File "/usr/local/lib/python3.6/dist-packages/urllib3/util/ssl_.py", line 359, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/usr/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.6/dist-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='idm.cox.com', port=443): Max retries exceeded with url: /SmMakeCookie.ccc?SMSESSION=<REDACTED_TOKEN>&PERSIST=0&TARGET=https%3A%2F%2Fidm.east.cox.net%2Floginss%2Fget%3FreturnURL%3Dhttps%253A%252F%252Fwww.cox.com%252Fresaccount%252Fhome.cox (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/cox_usage.py", line 45, in <module>
    browser.submit(login_form, login_page.url)
  File "/usr/local/lib/python3.6/dist-packages/mechanicalsoup/browser.py", line 213, in submit
    response = self._request(form, url, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/mechanicalsoup/browser.py", line 196, in _request
    return self.session.request(method, url, files=files, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 644, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 644, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 222, in resolve_redirects
    **adapter_kwargs
  File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 511, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='idm.cox.com', port=443): Max retries exceeded with url: /SmMakeCookie.ccc?SMSESSION=<REDACTED_TOKEN>&PERSIST=0&TARGET=https%3A%2F%2Fidm.east.cox.net%2Floginss%2Fget%3FreturnURL%3Dhttps%253A%252F%252Fwww.cox.com%252Fresaccount%252Fhome.cox (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))
ntalekt commented 6 years ago

Yes it's happening to me too. I tried to troubleshoot a little but didn't have time to fully look into it yet.

At first I thought it was an SSL issue too but I'm not sure. Currently when I login manually it requests the last 4 of my SSN before continuing. I figured that migt be part of the issue as I don't remember that before.

ntalekt commented 6 years ago

Script updated. I disabled SSL verification in order to get my automations working again. Still trying to find the root cause.