HTTPSConnectionPool SSL Error certificate verify failed

馋奶兔 提交于 2021-01-29 05:40:32

问题


I'm working on web scraping some particular websites and therefor I use the python 3 requests package and beautifulsoup. While processing a test over some websites I got this error :

requests.exceptions.SSLError: HTTPSConnectionPool(host='autoglassbodyrepair.lawshield.co.uk', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))


import requests as rq
import bs4

current_url = 'autoglassbodyrepair.lawshield.co.uk'
try:
   req = rq.get(current_url)
except rq.exceptions.RequestException as e:
   print(e)
else:
   soup = bs4.BeautifulSoup(r.content, "html.parser")
   text = soup.findAll(text = True)

When I try over my browser it shows me that the certificate is expired yet I can process to the page with https barred and turned to red. What I want is if there's an exception which won't allow me to access the page I'd just ignore it and get to the next page to process but if there's no exception I'd process the current page and ignore those SSl certificate.

Thanks in advance for your help !


回答1:


I got it, it just need to ignore the certificate as the code below, you would get a warning as insecure connection.

req = rq.get(current_url, verify = False)



来源:https://stackoverflow.com/questions/55746814/httpsconnectionpool-ssl-error-certificate-verify-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!