【问题标题】:AttributeError: module 'shodan' has no attribute 'Shodan'AttributeError:模块“shodan”没有属性“Shodan”
【发布时间】:2019-09-12 09:37:53
【问题描述】:

我需要使用 shodan API 执行 BULK whois 查询。

我遇到了这段代码

import shodan
api = shodan.Shodan('inserted my API-KEY- within single quotes')
info = api.host('8.8.8.8')

运行模块后出现以下错误:

回溯(最近一次通话最后一次):

中的文件“C:/Users/PIPY/AppData/Local/Programs/Python/Python37/dam.py”,第 1 行 进口小单

中的文件“C:/Users/PIPY/AppData/Local/Programs/Python/Python37\shodan.py”,第 2 行 api = shodan.Shodan('上面插入的 API KEY')
AttributeError: 模块 'shodan' 没有属性 'Shodan'

我正在学习 python,但脚本/编程经验有限。

你能帮帮我吗?

干杯

【问题讨论】:

  • 您是如何安装shodan 库的?
  • 在我使用过的命令提示符中:pip install shodan 然后 shodan init "my api key" 并且 o/p 是"成功初始化"

标签: python shodan


【解决方案1】:

你似乎有dam.pyshodan.py——Python 默认从模块目录导入,所以安装的shodan 包被屏蔽了。

尝试将shodan.py 重命名为例如shodan_test.py(当然还有修复任何导入等)。

【讨论】:

  • 我已重命名文件,现在出现以下错误 ModuleNotFoundError: No module named 'shodan'。我试图再次安装它,但给了我一个“要求已经满足:”消息的列表
【解决方案2】:

我已经通过在 C:\Users\PIPY\AppData\Local\Programs\Python\Python37\Scripts>pip install shodan 下重新安装 shodan 模块解决了这个问题

感谢 AKX 的帮助。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,但是在将我的文件重命名为不同于 shodan.py 的文件后,我还必须删除已编译的类 shodan.pyc 以避免错误。

    另外,如果您安装了多个版本的 python,即 python2 和 python3,请使用

    python -m pip install shodan 而不是pip install shodan,以确保您将库安装在用于执行脚本的相同版本的 shodan 中。

    如果您使用python3 shodan_test.py 执行脚本,请使用python3 -m pip install shodan

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-14
      • 2019-02-18
      • 1970-01-01
      • 2013-01-23
      • 2020-01-01
      • 2019-07-20
      • 2021-11-05
      相关资源
      最近更新 更多