0

I'm attempting to write a program that grabs data from my password protected gradebook and analyzes it for me because my university's gradebook doesn't automatically calculate averages. I'm running into issues at the very beginning of my program and it's growing more and more frustrating. I'm running on Python 2.7.9.

This is the Code.

import logging
import requests
import re
url = "https://learn.ou.edu/d2l/m/login"

s = requests.session()
r = s.get(url,verify = False)

This is the error that is occurring.

Traceback (most recent call last):
  File "/Users/jackson/Desktop/untitled folder/Grade Calculator.py", line 7, in <module>
    r = s.get(url,verify = False)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 473, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 461, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
SSLError: EOF occurred in violation of protocol (_ssl.c:581)

Even weirder, this only happens with the gradebook URL. When I use a different URL such as "http://login.live.com", I get this error.

Warning (from warnings module):
  File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 734
    InsecureRequestWarning)
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html

Does anybody know what I could to to fix this issue? Thanks, Jackson.

Jackson Blankenship
  • 475
  • 2
  • 7
  • 19

1 Answers1

1

Requests does not support so you need subclass the HTTPAdapter

from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import ssl

class MyAdapter(HTTPAdapter):
    def init_poolmanager(self, connections, maxsize, block=False):
        self.poolmanager = PoolManager(num_pools=connections,
                                       maxsize=maxsize,
                                       block=block,
                                       ssl_version=ssl.PROTOCOL_TLSv1)


import logging
import requests
import re
url = "https://learn.ou.edu/d2l/m/login"
s = requests.session()
s.mount('https://', MyAdapter())
r = s.get(url,verify = False)

print r.status_code

Gives status code:

200

This is answered here

Community
  • 1
  • 1
Tanveer Alam
  • 5,185
  • 4
  • 22
  • 43