Skip to main content
 首页 » 编程设计

python之ImportError:无法导入名称 WebAPI

2024年08月29日48lvdongjie

我想使用“shodan”API,但它不太适合我。

首先我在终端 easy_install shodan 中执行了这个命令 这是输出:

$easy_install shodan 
Searching for shodan 
Best match: shodan 0.8.1 
Processing shodan-0.8.1-py2.7.egg 
shodan 0.8.1 is already the active version in easy-install.pth 
 
Using /usr/local/lib/python2.7/dist-packages/shodan-0.8.1-py2.7.egg 
Processing dependencies for shodan 
Finished processing dependencies for shodan 

然后我写了我的代码:

#! /usr/bin/python en 
 
    from shodan import WebAPI 
 
    SHODAN_API_KEY = "Key" 
 
    api = WebAPI(SHODAN_API_KEY) 
 
 
    # Wrap the request in a try/ except block to catch errors 

它给了我一个错误:

ImportError: cannot import name WebAPI 

我搜索了类似的问题,有些答案是更改文件名,有些是删除 pyc 文件。我尝试了这两个答案,但它也不起作用。

请您参考如下方法:

您的脚本名称是什么?如果您的脚本名称是“shodan”,即与 Shodan 库同名,则可能会发生名称冲突。 Python 3 也存在导致一些导入问题的问题,但如果您使用的是最新版本的 Shodan API 库,则该问题应该已解决。我赞同 luc 的评论,即缩进看起来不对,因此您还需要修复它才能执行脚本。