Python的request.get()使用verify = False抛出SSLError

时间:2017-12-05 20:53:55

标签: python python-requests

我正在为ThePirateBay组合一个简单的界面(使用镜像),并且requests.get()正在返回SSLError - 我正在指定verify = False,因为其他帖子建议没有运气。我在MacOS Sierra上运行Python 2.7.10。

from bs4 import BeautifulSoup
import requests

url = "https://www.fastbay.net"
categories = {'anime': 1,
        'software': 2,
        'games': 3,
        'adult': 4,
        'movies': 5,
        'music': 6,
        'other': 7,
        'series': 8,
        'books': 9}
sort = ['created_at', 'size', 'seeders', 'leechers']


class PirateBayAPI(object):


_instance = None

def __new__(cls, *args, **kwargs):
    if not cls._instance:
        cls._instance = super(PirateBayAPI, cls).__new__(
            cls, *args, **kwargs)
    return cls._instance

def search(self, term, category='all', sort_criteria=None, asc=False):
    global url, categories, sort
    term = term.replace(' ','%20')
    resource = "%s/search/%s" % (url, term)

    req = requests.get(resource, verify=False)
    soup = BeautifulSoup(req.content)
    res = []

    for torrent in soup.findAll('tr'):
        try:
            date = torrent.find('td', attrs={'class': 'date-row'}).text
            size = torrent.find('td', attrs={'class': 'size-row'}).text
            seeders = torrent.find('td', attrs={'class': 'seeders-row'}).text
            leechers = torrent.find('td', attrs={'class': 'leechers-row'}).text
            magnet_link = torrent.find('a', attrs={'title': 'MAGNET LINK'})['href']
            link = "%s%s" % (url, torrent.findAll('a')[1]['href'])
            name = torrent.find('span').text
            t = {'date': date, 'size': size, 'seeders': int(seeders), 'leechers': int(leechers), 'magnet_link': magnet_link, 'name': name, 'link': link}
            res.append(t)
        except:
            pass
    return res

请原谅班级缩进......:)

返回的错误是:

requests.exceptions.SSLError: HTTPSConnectionPool(host='www.fastbay.net', port=443): Max retries exceeded with url: /search/walking%20dead (Caused by SSLError(SSLError(1, u'[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)'),))

谢谢!

0 个答案:

没有答案