import cookielib ModuleNotFoundError: No module named 'cookielib'

本文详细介绍Python3中模块名称变更,如cookielib改为http.cookiejar,urllib2改为urllib.request,以及raw_input变为input等关键信息。同时,提醒开发者注意Python3默认编码为Unicode,避免不必要的警告。
部署运行你感兴趣的模型镜像
  1. ModuleNotFoundError: No module named ‘cookielib’
    C:\Users\abc\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/abc/.PyCharmCE2019.3/config/scratches/scratch_1.py
    Traceback (most recent call last):
    File “C:/Users/abc/.PyCharmCE2019.3/config/scratches/scratch_1.py”, line 3, in
    import cookielib
    ModuleNotFoundError: No module named ‘cookielib’

Process finished with exit code 1

Python3中,**import cookielib 改成 import http.cookiejar,将所有cookielib **也改成 http.cookiejar

  1. 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)

  1. NameError: name ‘raw_input’ is not defined

Python 3中用**input()替换raw_input() **

  1. 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” 即 soup = BeautifulSoup(html_doc, “html.parser”)**

出自:https://www.cnblogs.com/Tanwheey/p/10220585.html

您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值