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

查看:393
本文介绍了请求s.get(url,verify = False)错误[Python]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图编写一个程序,该程序从受密码保护的成绩簿中获取数据并为我分析数据,因为我所在大学的成绩簿不会自动计算平均值.我在程序刚开始时就遇到了问题,并且越来越令人沮丧.我在Python 2.7.9上运行.

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.

这是代码.

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)

即使很奇怪,也只会发生在成绩簿URL上.当我使用其他URL,例如" http://login.live.com 时,出现此错误.

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.

推荐答案

请求不支持,因此您需要将HTTPAdapter

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

给出状态码:

200

此处

这篇关于请求s.get(url,verify = False)错误[Python]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆