You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyCharm中报错AttributeError:module 'requests' has no attribute 'get'求助

解决AttributeError: module 'requests' has no attribute 'get'错误

运行以下调用Kanye名言API的Python代码时,出现AttributeError: module 'requests' has no attribute 'get'错误:

from tkinter import *
import requests


def get_quote():
    response = requests.get('https://api.kanye.rest')
    response.raise_for_status()
    data = response.json()
    quote = data["quote"]
    canvas.itemconfig(quote_text, text=quote)


window = Tk()

window.title("Kanye Says...")
window.config(padx=50, pady=50)
canvas = Canvas(width=300, height=414)
background_img = PhotoImage(file="background.png")
canvas.create_image(150, 207, image=background_img)
quote_text = canvas.create_text(150, 207, text="Kanye Quote Goes HERE", width=250, font=("Arial", 30, "bold"),fill="white")


canvas.grid(row=0, column=0)

kanye_img = PhotoImage(file="kanye.png")
kanye_button = Button(image=kanye_img, highlightthickness=0.1, command=get_quote)
kanye_button.grid(row=1, column=0)

window.mainloop()

解决方法:

  • 检查脚本文件名:不要将自己的Python脚本命名为requests.py,这会与官方requests模块重名,导致导入的是本地脚本而非官方模块。将脚本改名(比如kanye_quote.py),同时删除目录下自动生成的requests.pyc文件(如果存在)。
  • 确认requests模块安装状态:在PyCharm终端执行pip show requests,查看模块是否已正确安装。若未安装,执行pip install requests重新安装。
  • 验证PyCharm解释器配置:通过File → Settings → Project: [项目名] → Python Interpreter查看当前解释器的已安装包列表,确保requests在其中。没有的话点击+号搜索并安装。
  • 清理PyCharm缓存:点击File → Invalidate Caches...,选择Invalidate and Restart重启IDE,清除可能存在的模块缓存问题。

内容的提问来源于stack exchange,提问作者Shivam Mishra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 16:42:36