开发者社区> zchd> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

初学python 遇到的坑

简介: 这最近人工智能比较火,看了一下大多都是python的代码,最近看看python 的代码,一出来就遇到了坑,空格的问题先不说了直接上代码吧 # coding = utf-8 import urllib.
+关注继续查看

这最近人工智能比较火,看了一下大多都是python的代码,最近看看python 的代码,一出来就遇到了坑,空格的问题先不说了直接上代码吧

# coding = utf-8
import urllib.request
#import ssl

#ssl._create_default_https_context = ssl._create_unverified_context
response = urllib.request.urlopen('https://www.douban.com/')
print(response.read().decode('utf-8'))

  

python python3 log_python.py
Traceback (most recent call last):
File "/usr/local/homebrew/Cellar/python3/3.6.0/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 "/usr/local/homebrew/Cellar/python3/3.6.0/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 "/usr/local/homebrew/Cellar/python3/3.6.0/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 "/usr/local/homebrew/Cellar/python3/3.6.0/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 "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
self.do_handshake()
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "log_python.py", line 6, in <module>
response = urllib.request.urlopen('https://www.douban.com/')
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/usr/local/homebrew/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/usr/local/homebrew/Cellar/python3/3.6.0/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 "/usr/local/homebrew/Cellar/python3/3.6.0/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:749)>

出了一堆的错,然后在 http://stackoverflow.com/questions/27835619/ssl-certificate-verify-failed-error 找到了答案:

要引入 一个ssl 的模块,然后,就没有然后了

 

Could not fetch URL https://pypi.python.org/simple/nltk/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) - skipping
  Could not find a version that satisfies the requirement nltk (from versions: )
No matching distribution found for nltk

报了上面的错,下面的语句解决.

pip --trusted-host pypi.python.org install

<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645

 报了上面的错,下面的语句解决 

 

pip3 install certifi

 

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
初学Python——字典
一、定义 什么是字典? 字典是一种数据类型,是一系列数据的组合。 每一个数据单元都分为key和value,key也称主键,具有唯一性,不可重复。value可以理解成是key对应的值。 1 info={ 2 1:"wo shi shei", 3 2:"sun wu kong", 4 "stu001":"alex", 5 "stu002":"zhangyang", 6 7 } 如上,key可以是int型,也可以是字符型,value亦是。
988 0
深度之眼(十三)——Python:类-面向对象的编程(下)
深度之眼(十三)——Python:类-面向对象的编程(下)
0 0
深度之眼(十三)——Python:类-面向对象的编程(上)
深度之眼(十三)——Python:类-面向对象的编程(上)
0 0
深度之眼(九)——python函数--面向过程的编程(下)
深度之眼(九)——python函数--面向过程的编程(下)
0 0
深度之眼(九)——python函数--面向过程的编程(上)
深度之眼(九)——python函数--面向过程的编程(上)
0 0
Python编程:MySQLdb模块对数据库的基本增删改查操作
Python编程:MySQLdb模块对数据库的基本增删改查操作
0 0
Python编程:entry_points将Python模块转变为命令行工具
Python编程:entry_points将Python模块转变为命令行工具
0 0
Python编程:SQLAlchemy查询数据没有变化
遇到一个问题,使用一条相同的sql,多次查询数据库,每次数据都一样,而且数据库更新了,也没有查到新数据 经过Google,发现是SQLAlchemy的缓存机制导致的 设置隔离级别参数isolation_level 就可以解决
0 0
Python编程:运行目录或zip压缩文件
Python编程:运行目录或zip压缩文件
0 0
+关注
zchd
架构,编程语言相关技术专家
文章
问答
文章排行榜
最热
最新
相关电子书
更多
给运维工程师的Python实战课
立即下载
Python 脚本速查手册
立即下载
ACE 区域技术发展峰会:Flink Python Table API入门及实践
立即下载