python 3.x报错:No module named 'cookielib'或No module named 'urllib2'
1. ModuleNotFoundError: No module named 'cookielib'

Python3中,import cookielib改成 import http.cookiejar,然后方法里cookielib也改成 http.cookiejar。
2. ModuleNotFoundError: No module named 'urllib2'
Python 3中urllib2用urllib.request替代。
在Python官方文档里面已有说明:
Note:
The urllib2 module has been split across several modules in Python 3.0 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to 3.0.
from urllib.request import urlopen
response = urlopen("http://www.google.com")
html = response.read()
print(html)
3. NameError: name 'raw_input' is not defined
Python 3中用input()替换raw_input()
4. UserWarning: You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.
注意这句:warnings.warn("You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.") 原因:python3 缺省的编码是unicode, 再在from_encoding设置为utf8, 会被忽视。
Python 3中soup = BeautifulSoup(html_doc, "html.parser", from_encoding="utf-8")这一句中删除from_encoding="utf-8"
------------------------------------------------------Tanwheey-------------------------------------------------------------------------
爱生活,爱工作。
python 3.x报错:No module named 'cookielib'或No module named 'urllib2'的更多相关文章
- [转]happybase1.0 报错:ThriftPy does not support generating module with path in protocol 'f'
happybase1.0 报错:ThriftPy does not support generating module with path in protocol 'f' 2016-10-12 14: ...
- vue解决启动报错cjs loader.js Error: Cannot find module '../config'问题
vue解决启动报错cjs loader.js Error: Cannot find module '../config'问题 今天下载了一个开源项目一直运行不了,折腾了半天才找到问题所在,config ...
- 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence
python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte ...
- 【python】python安装tensorflow报错:python No matching distribution found for tensorflow==1.12.0
python安装tensorflow报错:python No matching distribution found for tensorflow==1.12.0 python版本是3.7.2 要安装 ...
- mac下python环境pip报错[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) 的解决方法
1.mac下python环境pip报错: issuserdeMacBook-Pro:~ issuser$ pip install pyinstallerCollecting pyinstaller ...
- Django中修改DATABASES后,执行python manage.py ****报错!UnicodeEncodeError
Django中修改DATABASES后,执行python manage.py ****报错!UnicodeEncodeError: 'latin-1' codec can't encode chara ...
- python 安装模块报错 response.py", line 302, in _error_catcher
python 安装模块报错 Exception:Traceback (most recent call last): File "/usr/share/python-wheels/urlli ...
- 【原创】大叔经验分享(11)python引入模块报错ImportError: No module named pandas numpy
python应用通常需要一些库,比如numpy.pandas等,安装也很简单,直接通过pip # pip install numpyRequirement already satisfied: num ...
- python导入模块报错:ImportError: No module named mysql.connector(安装 mysql)
python的版本是 $ python --version Python 2.7.12 报错代码如下 import mysql.connector 报错信息是 ImportError: No modu ...
随机推荐
- AtCoder4351 Median of Medians 二分, 树状数组
题目大意 定义一个从小到大的数列的中位数为第 $ \frac{n}{2}+1 $ 项.求一个序列的所有连续子序列的中位数的中位数. $ (n \leqslant 100000)$ 问题分析 由于\(n ...
- sqli-labs(4)
sqli-libs(4)通关过程 0x01爱之初体验 首先我们进行注入试探 发现我们的单引号 回显事正常的 双引号回显反而是错误的 查看源码我们发现 多了一个给id赋值的语句 我们在php上面执行一下 ...
- [BZOJ2286][Sdoi2011]消耗战(虚树上DP)
2286: [Sdoi2011]消耗战 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6457 Solved: 2533[Submit][Statu ...
- plt.plot() 无法使用参数ax
问题参考 TypeError: inner() got multiple values for keyword argument 'ax' fig, ax=plt.subplots(2,1) plt. ...
- MySQL + centos +主从复制
MYSQL(mariadb) MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可.开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的 ...
- 【python】windows更改jupyter notebook(ipython)的默认打开工作路径
写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...
- 在一般处理程序中使用session
public class Handler1 : IHttpHandler, IRequiresSessionState 需要继承 IRequiresSessionState接口,告诉程序要使用sess ...
- mybayis分页插件
转载自 https://www.cnblogs.com/ljdblog/p/6725094.html
- java 深入HashMap
HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做一个整体来处理,系统会根据 ...
- LoadRunner 技巧之 集合点设置
LoadRunner 技巧之 集合点设置 Loadrunner 技巧已经整理4篇了,你个一定疑问,这些知识点,网上随处可见.确实,由于长时间没有使用这个工具,造成我的一些概念开始在大脑中模糊,我只是用 ...