【python3】urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>
在玩爬虫的时候,针对https ,需要单独处理。不然就会报错:
解决办法:引入 ssl 模块即可
核心代码
- imort ssl
- ssl._create_default_https_context = ssl._create_unverified_context
完整代码如下:
- # coding=utf-8
- import re
- import urllib.request
- import ssl
- # 获取html内容
- def getHtml(url):
- page = urllib.request.urlopen(url)
- html = page.read()
- html = html.decode('utf-8')
- return html
- # 获取title
- def get_title(html):
- reg = r'<title>(.*)</title>'
- content_title = re.compile(reg)
- result = re.findall(content_title, html)
- return result
- # 创建ssl证书
- ssl._create_default_https_context = ssl._create_unverified_context
- url = "https://www.cnblogs.com"
- html = getHtml(url)
- title = get_title(html)
- print(title)
结果:
【python3】urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>的更多相关文章
- 【Python】【BugList13】req = requests.get(url=target)报错: (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)')
[代码] # -*- coding:UTF-8 -*- import requests if __name__ == '__main__': target = 'https://unsplash.co ...
- 豆瓣 URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:719)>
import urllib.request as urlrequest #import ssl#ssl._create_default_https_context = ssl._create_unve ...
- urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>
解决办法: import ssl # 在请求之前加上 ssl._create_default_https_context = ssl._create_unverified_context
- 执行buildman --fetch-arch arm提示"urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>"如何处理?
答: 在uboot源码的tools/buildman/toolchain.py中取消证书验证,修改内容如下: diff --git a/tools/buildman/toolchain.py b/to ...
- Let'sencrypt.sh 抛出异常: Response: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)>
起因 今天网站的SSL证书过期了,打算重新申请,运行 Let'sencrypt.sh 的时候抛出了这么个异常. 一番搜索,发现居然找不到直接的答案.没有直接的答案就只能通过间接的答案来解决了. 希望我 ...
- Mac 下python3 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 解决方法
原文:http://blog.yuccn.net/archives/625.html python3.6下使用urllib 的request进行url 请求时候,如果请求的是https,请求可以会出现 ...
- urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed解决办法
描述 今天学习写一篇用python(我的是Python 3.6)登录知乎网(https://www.zhihu.com) 的爬虫,测试时报错:urlopen error [SSL: CERTIFICA ...
- python3 使用urllib报错urlopen error EOF occurred in violation of protocol (_ssl.c:841)
python3源码: import urllib.request from bs4 import BeautifulSoup response = urllib.request.urlopen(&qu ...
- #python# error:urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>
设置代理后访问网页报错,百度有人说地址拼写不对,确认拼写后依然报错 因为使用的是xici免费代理,想到可能代理不可用造成getaddrinfo failed, 更换其他代理,error消失
随机推荐
- openssl创建自己的CA certificate
Create a Certificate Authority private key (this is your most important key): $ openssl req -new -ne ...
- PLSQL Developer删除奇葩表出现异常ORA-00942: 表或试图不存在
简单描述一下问题:发现数据库里有两个名称相同的表,不同的是PLSQL Developer里一个表名显示是大写,而另一个表名显示是小写 一般情况下,无论建表语句是大写,还是小写,因Oracle是区分大小 ...
- yii2 页面渲染方法解析
render渲染.renderPartial渲染部分.renderContent.renderAjax.renderFile ① render显示view和layout ② renderPartial ...
- linux 内存分页
内存是计算机的主存储器.内存为进程开辟出进程空间,让进程在其中保存数据.我将从内存的物理特性出发,深入到内存管理的细节,特别是了解虚拟内存和内存分页的概念. 内存 简单地说,内存就是一个数据货架.内存 ...
- 微信小程序省市区选择器对接数据库
前言,小程序本身是带有地区选着器的(网站:https://mp.weixin.qq.com/debug/wxadoc/dev/component/picker.html),由于自己开发的程序的数据是很 ...
- 临时解决Apache服务器假死的参数配置
<IfModule mpm_prefork_module> StartServers MinSpareServers MaxSpareServers MaxClients MaxReque ...
- linux如何通过脚本来修改用户的密码?脚本自动化修改用户密码?
需求描述: linux环境中在创建用户的时候,涉及到修改用户的密码,一般是通过passwd命令进行修改,需要多次的确认,这里考虑通过一条命令直接对密码进行修改 不需要进行交互的方式.在此记录. 操作过 ...
- 【12月06日】A股全市场情绪指标整理分析
1. A股全市场的股权质押比例 2018年11月30日,A股全市场,质押股数占全市场总股本数比:9.997%,最近2周出现了3.2%的轻微回落.同历史时期相比,仍然处于高位. 2. A股全市场的解禁市 ...
- A股最新的自由现金流和折现估值查询
A股最新的自由现金流折现估值,利用自由现金流折现的经典公式,采用 8%.9%.10%.11%.12%.15% 等贴现率来进行估值. SH600000:浦发银行的最新自由现金流和折现估值模型: 浦发银行 ...
- 8 -- 深入使用Spring -- 3...1 Resource实现类ServletContextResource
8.3.1 Resource实现类------ServletContextResource:访问相对于ServletContext路径下的资源的实现类. 4.访问应用相关资源 Spring提供了Ser ...