encode_chunked=req.has_header('Transfer-encoding'))问题解决方法
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/simley/PycharmProjects/hello/imooc/test.py", line 14, in <module>
resp = request.urlopen(req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)>
Process finished with exit code
添加如下代码:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
# -*-coding:utf-8-*-
from urllib import request
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
req = request.Request("https://www.baidu.com")
req.add_header('User-Agent',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36')
resp = request.urlopen(req)
resp = request.urlopen(req)
print(resp.read().decode('utf-8'))
————————————————
版权声明:本文为CSDN博主「Road to be king」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011046452/article/details/80586822
encode_chunked=req.has_header('Transfer-encoding'))问题解决方法的更多相关文章
- Python爬虫编程常见问题解决方法
Python爬虫编程常见问题解决方法: 1.通用的解决方案: [按住Ctrl键不送松],同时用鼠标点击[方法名],查看文档 2.TypeError: POST data should be bytes ...
- WingIDE中文乱码问题解决方法
WingIDE中文乱码问题解决方法 安装完WingIDE后,首次运行python脚本时,若脚本中含有UTF-8中文,在Debug I/O输出框中,全部变成了乱码. 这时其实我们设置下WingIDE的编 ...
- 【转】asp.net Cookie值中文乱码问题解决方法
来源:脚本之家.百度空间.网易博客 http://www.jb51.net/article/34055.htm http://hi.baidu.com/honfei http://tianminqia ...
- soapUI参数中文乱码问题解决方法 (groovy脚本中文乱码)
soapUI参数中文乱码问题解决方法 可能方案1: 字体不支持中文,将字体修改即可: file-preferences-editor settings-select font 修改字体,改成能显示中文 ...
- python3 库pandas写入csv格式文件出现中文乱码问题解决方法
python3 库pandas写入csv格式文件出现中文乱码问题解决方法 解决方案: 问题是使用pandas的DataFrame的to_csv方法实现csv文件输出,但是遇到中文乱码问题,已验证的正确 ...
- soapUI参数中文乱码问题解决方法&soap UI工具进行web接口测试
soapUI参数中文乱码问题解决方法 可能方案1: 字体不支持中文,将字体修改即可: file-preferences-editor settings-select font 修改字体,改成能显示中文 ...
- tomcat启动控制台中文乱码问题解决方法
tomcat启动控制台中文乱码问题解决方法,修改tomcat安装路径/conf/logging.properties文件 java.util.logging.ConsoleHandler.encodi ...
- win7中VS2010中安装CSS3.0问题解决方法
win7中VS2010中安装CSS3.0问题解决方法 在安装Standards Update for VS2010 SP1后,VS2010中没有CSS3.0问题,以下是我的解决方法 1.首先去官网 ...
- win8安装SQL Server 2005问题解决方法
win8安装SQL Server 2005问题解决方法 1.正常安装任一版本的SQL Server 2005(最好安装企业版). 2.安装到SqlServer服务的时候提示启动服务失败(提示重试的时候 ...
随机推荐
- jQuery中的DOM操作【续】
一.复制节点$(选择器字符串).clone(false) [返回克隆的节点对象]参数:false,浅复制,复制元素但不复制元素中所绑定的事件[默认为false]true,深复制,复制元素且复制元 ...
- 动态路由 RIP
不同网段之间进行通信,中间有多个路由器的情况下,我们可以通过配置RIP动态路由来实现数据转发. 实验拓扑 如图所示连接,地址规划如下: 名称 接口 IP地址 R1 f0/0 192.168.10.1/ ...
- 【Docker】Docker容器中安装vim命令
1)先执行 apt-get update 2) 再执行 apt-get install vim
- h5 js复制 功能
感谢 http://www.jq22.com/webqd6003 var copy1 = document.getElementById('copy1'); var copy2 = document. ...
- kubernetes集群证书过期之后--转发
步骤 如果有多master,需要在每个master上进行以下操作. 需要进行以下步骤 重新生成证书 重新生成对应的配置文件 重启docker 和 kubelet 拷贝kubectl 客户端文件 [ro ...
- zabbix--微信告警
zabbix 微信告警机制 zabbix 告警机制有很多,比如邮件.微信.电话.短信等等.很多,但是像电话和短信都是有钱人玩的,我们这些穷屌丝玩玩 微信 邮件 就可以了. 参考:https://git ...
- PTA 树的遍历(根据后序中序遍历输出层序遍历)
给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列.这里假设键值都是互不相等的正整数. 输入格式:输入第一行给出一个正整数N(≤30),是二叉树中结点的个数.第二行给出其后序遍历序列.第 ...
- Bag of Tricks for Image Classification with Convolutional Neural Networks笔记
以下内容摘自<Bag of Tricks for Image Classification with Convolutional Neural Networks>. 1 高效训练 1.1 ...
- Ofbiz项目学习——阶段性小结——插入数据
一.通用插入操作 /** * * 编写一个服务createUomOneDemo, * 该服务的作用是在表Uom中增加一条记录,其中: * 字段uomId的值为“BaseLineProduct”. * ...
- list数组排序 Collections 按Date时间降序排列
@ResponseBody @RequestMapping(value = {"K12", "12"}) public String refurbishLigh ...