请求s.get(url,verify = False)错误[Python]

时间:2014-12-16 07:18:29

标签: python login passwords python-requests username

我试图编写一个程序,从我的密码保护成绩单中抓取数据并为我分析,因为我的大学成绩簿并不能自动计算平均值。我在项目一开始就遇到了问题,而且越来越令人沮丧。我正在使用Python 2.7.9。

这是守则。

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

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

这是正在发生的错误。

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)

即使更奇怪,这只发生在成绩簿网址上。当我使用其他网址,例如&#34; http://login.live.com&#34;时,我收到此错误。

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

有人知道我能解决这个问题吗?谢谢,杰克逊。

1 个答案:

答案 0 :(得分:1)

请求不支持,因此您需要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

提供状态代码:

200

已回答here