Estoy practicando el código de 'Web Scraping with Python' y sigo teniendo este problema con el certificado:
from urllib.request import urlopen from bs4 import BeautifulSoup import re pages = set() def getLinks(pageUrl): global pages html = urlopen("http://en.wikipedia.org"+pageUrl) bsObj = BeautifulSoup(html) for link in bsObj.findAll("a", href=re.compile("^(/wiki/)")): if 'href' in link.attrs: if link.attrs['href'] not in pages: #We have encountered a new page newPage = link.attrs['href'] print(newPage) pages.add(newPage) getLinks(newPage) getLinks("")el error es:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1049)>Por cierto, también estaba practicando scrapy, pero seguía teniendo el problema: command not found: scrapy (probé todo tipo de soluciones en línea pero ninguna funciona... realmente frustrante)
Una vez me tropecé con este problema. Si usa macOS, vaya a Macintosh HD > Aplicaciones > carpeta Python3.6 (o cualquier versión de python que esté usando) > haga doble clic en el archivo "Instalar Certificates.command". :D
para usar SSL no verificado, puede agregar esto a su código:
import ssl ssl._create_default_https_context = ssl._create_unverified_contextEste comando de terminal:
open /Applications/Python\ 3.7/Install\ Certificates.command
Encontrado aquí: https://stackoverflow.com/a/57614113/6207266
Me lo resolvió. Con mi configuración
pip install --upgrade certifi
no tuvo impacto.