Python2.7使用urllib2访问https报错,python2.7urllib2,想要访问https网站,
Python2.7使用urllib2访问https报错,python2.7urllib2,想要访问https网站,
想要访问https网站,获取网页的源代码,如:https://www.baidu.com
源码如下:
f = urllib2.urlopen("https://www.baidu.com/")buf = f.read()f.close()
结果报错:
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>
Python版本:2.7.9
运行平台:Windows
https 访问,使用pycurl更方便一些~
>>> import urllib2>>> f = urllib2.urlopen("https://www.baidu.com/")>>> buf = f.read()>>> f.close()>>> buf'<html>\r\n<head>\r\n\t<script>\r\n\t\tlocation.replace(location.href.replace("https://","http://"));\r\n\t</script>\r\n</head>\r\n<body>\r\n\t<noscript><meta http-equiv="refresh" content="0;url=http://www.baidu.com/"></noscript>\r\n</body>\r\n</html>'>>>
在Mac下运行是正常的,应该是你的环境下不支持SSL,Windows环境需要自行安装
附一下安装方法,希望能对你有帮助:
How to install Python ssl module on Windows?
编橙之家文章,
相关内容
- 求教RESTful设计实现方法的疑问,restful疑问,最近在写
- Python lambda作用范围的一点疑惑,pythonlambda,标题描述可
- Python实现函数调用新手遇到的问题,python函数调用新手
- 小白问python dict根据value取key值应该怎么写?,pythondict
- Python requests多线程抓取请求都报异常无解,pythonreques
- Python sys.path哪个命令可以代替append,sys.pathappend,如题。
- python3.x版本 通过urlopen打开一个以html结尾的网址 转换成
- python去重元给中有字典项怎么去重,python字典项,在 p
- Python pip install xlwings遇到error找不到原因,pipxlwings,按照
- 《Python编程实践》for语法使用啥意思,,《Python编程实践
评论关闭