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服务的时候提示启动服务失败(提示重试的时候 ...
随机推荐
- Linux errno 与 Python
以下均为Linux环境测试. 起因: 开发的一个程序,经常会由于内存不足而被kill掉,使用的是os.system函数执行的,返回值总是35072,当时没多想.后来由于一些原因,要模拟OOM 被kil ...
- 【Spring Boot】Spring Boot之利用Logstash将日志转换成以JSON的格式存储和输出
一.Logstash的作用 Logstash是一个完全开源的工具,它可以对日志进行收集.过滤,能非常方便地将日志转换成以JSON的格式存储和输出,并将其存储供以后使用. 二.整合Logstash的步骤 ...
- zabbix--监控MySQL主从状态
zabbix监控MySQL主从状态 搭建MySQL主从后,很多时候不知道从的状态是否ok,有时候出现异常不能及时知道,这里通过shell脚本结合zabbix实现监控并告警 一般情况下,在MySQL的从 ...
- Unity历史版本的文档
前言 在我们的开发过程中,如果要查找Unity文档,通常会有以下两种方式: 1. 打开Unity的官网,查找文档 2. 查找本地安装的Unity文档 但是Unity官网上的文档,总是当前最新版本的文档 ...
- 用Python打造了一个渗透测试暴力探测器
资源探测的作用 通过资源探测,我们可以在目标系统中发现文件.目录.活动.服务还有相关的参数,为下一步的行动提供信息参考. 一个开源的模糊测试数据库 https://github.com/fuzzdb- ...
- PID动图——很形象
p是控制现在,i是纠正曾经,d是管控未来! pid的公式: 其中Kp为比例带,TI为积分时间,TD为微分时间.PID控制的基本原理就是如此. pid的原理和代码,在木南创智的博客园中有很好的教程:ht ...
- 聊聊CMSIS-RTOS是什么东东
起因:发布自己翻译用的CMSIS_RTOS_Tutorial后,陆续收到网友关于“CMSIS-RTOS是干么的?”之类的问题,再次统一回复. 众所周知,实时操作系统是嵌入式领域的基石.而可选的嵌入式操 ...
- Spring启动,constructor,@PostConstruct,afterPropertiesSet,onApplicationEvent执行顺序
package com.xx; import javax.annotation.PostConstruct; import javax.annotation.Resource; import org. ...
- Java Polymorphism
Ability of an organism to take different shapes is polymorphism in bio world. A simplest definition ...
- 二叉堆的构建(Java)
package com.rao.linkList; /** * @author Srao * @className BinaryHeap * @date 2019/12/3 14:14 * @pack ...