我想使用“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 的评论,即缩进看起来错误,因此您还需要修复它才能执行脚本。
关于python - ImportError:无法导入名称 WebAPI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13555685/