2

我想使用“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 文件。我尝试了两个答案,但它也不起作用。

4

2 回答 2

3

你的剧本叫什么名字?如果您的脚本名称是“shodan”,即与 Shodan 库同名,则可能会发生名称冲突。Python 3 还有一个问题导致一些导入问题,但如果您使用的是最新版本的 Shodan API 库,则应该解决。而且我回应了 luc 的评论,即缩进看起来错误,因此您还需要修复它才能执行脚本。

于 2013-02-13T18:04:38.583 回答
0

我找到了我应该安装 py crypto 的答案

sudo apt-get install python-crypto

于 2014-01-12T14:38:12.587 回答