已经安装了requests 为什么在运行时还会有You need either charset_normalizer or chardet installed

img

import requests
import random
def get_list_json(list_url):
header = {
"Host": " search.51job.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36",
"Accept": "application/json",
"Accept - Encoding": "gzip, deflate, br"
}
response=requests.get(list_url,headers=header)
response.encoding = 'gbk'
print(response.text)

def main(keywords, pages):
for index in range(1, pages + 1):
url = " 【上海,python招聘,求职】-前程无忧 前程无忧为您提供上海,python招聘,求职信息。网聚全国各城市的人才信息,找好工作,找好员工,上前程无忧。 https://search.51job.com/list/020000,000000,0000,00,9,99,python,2,1.html%22.format (keywords, str(index))
print("正在爬取第" + str(index) + "页数据")
get_list_json(url)

if name == 'main':
main('python', 1)

卸载重装

需要依赖库chardet或chardet-normalizer支持,尝试在安装requests前先pip install chardet,或使用这样命令安装:
python -m pip install requests chardet

requests 没有安装完整。重新安装一下试试

试试

pip install requests -i http://pypi.douban.com/simple --trusted-host=pypi.douban.com

python pip install requests报错_肆方海木的博客-CSDN博客 闲来无事学python(爬虫),使用任何软件的第一步就是正确地安装它,安装requests模块报错>pip install requestsCollecting requests Using cached https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e87... https://blog.csdn.net/sinat_30126855/article/details/88846505
有帮助望采纳

试试新建一个python的虚拟环境,然后重新pip install requests。具体如何安装虚拟环境,请看我博客:vscode如何新建python虚拟环境。望采纳,谢谢!

装个anaconda就行了

requests模块依赖chardet模块检测页面的编码以在输出response.text的时候不输出乱码。
看你这样子是不是手动安装的?下个chardet试试。

  • 先卸载掉已安装的requests

    pip uninstall requests

  • 再执行安装命令:

    pip install requests