【问题标题】:I get an error when I try to get a site in Python当我尝试在 Python 中获取站点时出现错误
【发布时间】:2021-08-04 14:02:29
【问题描述】:
import whois
site = input('enter site : ')
M = whois.whois(site)
print(M)

当我输入时, enter site : google.com

我得到以下响应(错误):

Traceback (most recent call last):
  File "f:/Programming/project/Project/whois.py", line 1, in <module>
    import whois
  File "f:\Programming\project\Project\whois.py", line 4, in <module>
    M = whois.whois(site)
TypeError: 'module' object is not callable

【问题讨论】:

  • 堆栈跟踪中的文件路径不是通常安装模块的位置。你有一个名为 whois 的模块吗?
  • 您使用的是哪个 python 版本?你是用 pip 安装模块的吗?

标签: python whois


【解决方案1】:

您的文件名为whois.py。当您导入 whois 时,您导入的是您的文件,而不是您认为的包。运行whois.whois(...),您将自己称为函数。

重命名您的文件并重试。

【讨论】:

  • 我之前改过,又报错了
  • 没有名为“whois”的模块
  • @MiladRasooli 你是如何安装whois的?
  • pip install whois
【解决方案2】:

尝试:

M = whois.query(site)
print(M.__dict__)

query是获取网站whois数据的方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-02
    • 2020-03-19
    • 1970-01-01
    • 2021-03-19
    相关资源
    最近更新 更多