【问题标题】:certificate verify failed (_ssl.c:645)>” for one particuar domain一个特定域的证书验证失败 (_ssl.c:645)>”
【发布时间】:2016-08-19 20:44:56
【问题描述】:

对这个特定域的每个请求现在都以证书验证失败 (_ssl.c:645)>

结尾

我不确定是什么原因造成的。从昨晚开始,我一直在寻找答案,试图弄清楚如何解决它,但不知何故我无法让它运行。

我尝试了 pip uninstall -y certifi && pip install certifi==2015.04.28 但没有帮助。

这是我的代码:

def trade_spider(max_pages):
page = -1

partner_ID = 2
location_ID = 25


already_printed = set()

for page in range(0,20):
    response = urllib.request.urlopen("http://www.getyourguide.de/s/search.json?q=" + str(Region) +"&page=" + str(page))
    jsondata = json.loads(response.read().decode("utf-8"))
    format = (jsondata['activities'])
    g_data = format.strip("'<>()[]\"` ").replace('\'', '\"')
    soup = BeautifulSoup(g_data)



    hallo = soup.find_all("article", {"class": "activity-card activity-card-horizontal "})


    for item in hallo:
        headers = item.find_all("h3", {"class": "activity-card-title"})
        for header in headers:
            header_final = header.text.strip()
            if header_final not in already_printed:
                already_printed.add(header_final)



        prices = item.find_all("span", {"class": "price"})
        for price in prices:
            #itemStr += ("\t" + price.text.strip().replace(",","")[2:])
            price_final = price.text.strip().replace(",","")[2:]
            #if itemStr2 not in already_printed:
            #print(itemStr2)
                #already_printed.add(itemStr2)


        deeplinks = item.find_all("a", {"class": "activity-card-link"})
        for t in set(t.get("href") for t in deeplinks):
            #itemStr += "\t" + t
            deeplink_final = t
            if deeplink_final not in already_printed:
                #print(itemStr3)
                already_printed.add(deeplink_final)

        Language = "Deutsch"

        end_final = "Header: " + header_final + " | " + "Price: " + str(price_final) + " | " + "Deeplink: " + deeplink_final + " | " + "PartnerID: " + str(partner_ID) + " | " + "LocationID: " + str(location_ID)+ " | " + "Language: " + Language
        if end_final not in already_printed:
            print(end_final)
            already_printed.add(end_final)

trade_spider(int(Spider))

这是输出:

               Traceback (most recent call last):
   File "C:\Python34\lib\urllib\request.py", line 1240, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
   File "C:\Python34\lib\http\client.py", line 1083, in request
self._send_request(method, url, body, headers)
   File "C:\Python34\lib\http\client.py", line 1128, in _send_request
self.endheaders(body)
   File "C:\Python34\lib\http\client.py", line 1079, in endheaders
self._send_output(message_body)
   File "C:\Python34\lib\http\client.py", line 911, in _send_output
self.send(msg)
   File "C:\Python34\lib\http\client.py", line 854, in send
self.connect()
   File "C:\Python34\lib\http\client.py", line 1237, in connect
server_hostname=server_hostname)
   File "C:\Python34\lib\ssl.py", line 376, in wrap_socket
_context=self)
   File "C:\Python34\lib\ssl.py", line 747, in __init__
self.do_handshake()
   File "C:\Python34\lib\ssl.py", line 983, in do_handshake
self._sslobj.do_handshake()
   File "C:\Python34\lib\ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "C:/Users/Rj/Desktop/ crawling                                        scripts/GetyourGuide_International_Final.py", line 84, in <module>
trade_spider(int(Spider))
File "C:/Users/Raju/Desktop/scripts/GetyourGuide_International_Final.py", line 36, in trade_spider
response = urllib.request.urlopen("http://www.getyourguide.com/s/search.json?q=" + str(Region) +"&page=" + str(page))
File "C:\Python34\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:\Python34\lib\urllib\request.py", line 471, in open
response = meth(req, response)
File "C:\Python34\lib\urllib\request.py", line 581, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py", line 503, in error
result = self._call_chain(*args)
File "C:\Python34\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 686, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\Python34\lib\urllib\request.py", line 465, in open
response = self._open(req, data)
File "C:\Python34\lib\urllib\request.py", line 483, in _open
'_open', req)
File "C:\Python34\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 1283, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Python34\lib\urllib\request.py", line 1242, in do_open
raise URLError(err)

urllib.error.URLError:

有人可以帮帮我吗?任何反馈都非常感谢:)

【问题讨论】:

  • 这种错误通常表示服务器配置错误,更准确地说是服务器发送的证书链出现故障。
  • 我无法在 ubuntu 上使用 python2 或 3 复制您的问题

标签: python python-3.x ssl web-crawler python-requests


【解决方案1】:

我会通过检查 openssl 是否可以验证证书来进一步调查:

openssl s_client -showcerts -connect www.getyourguide.de:443

【讨论】:

  • OK,证书由 Let's Encrypt Authority X3 签名
  • 2015 年 9 月 14 日,Let's Encrypt 发布了它的第一个证书,该证书用于域 helloworld.letsencrypt.org。同一天,ISRG 向 Mozilla、Microsoft、Google 和 Apple 提交了其根程序应用程序。 en.wikipedia.org/wiki/Let%27s_Encrypt
  • 我怀疑 CA 是否在 certi==2015.0.28 中,因为它仅在 9 月应用
  • 感谢您的反馈。我现在应该怎么做才能解决问题?你有推荐吗?
  • 尝试安装certifi==2016.08.08
猜你喜欢
  • 2018-07-29
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-18
  • 2017-06-01
  • 2017-02-05
  • 2023-03-03
相关资源
最近更新 更多