我想在python中列出一次我的脚本搜索特定的字符串,但是我还想添加国家代码的前两个字母,但是当我尝试时,它会显示invalid KeyError:“country_code”,但是api显示位置国家代码我怎么才能做到呢?在
#!/usr/bin/python
import shodan
SHODAN_API_KEY="xxxxxxxxxxxxxxxxxxxx"
api = shodan.Shodan(SHODAN_API_KEY)
try:
# Search Shodan
results = api.search('ProFTPd-1.3.3c')
# Show the results
for result in results['matches']:
print '%s' % result['ip_str']
print '%s' % result['country_code']
except shodan.APIError, e:
print 'Error: %s' % e
我想这就是您在Python中使用的方法 https://github.com/achillean/shodan-python/blob/master/shodan/client.py#L324 它会触发:
Shodan API文档: https://developer.shodan.io/api 查看/shodan/host/searchAPI
我刚看到答案在你的问题,但你吃了一封来自地点的信。在
试试这个:
^{pr2}$所以你们要找的字段在那个里,但它在另一本字典里。在
我建议下次仔细阅读API文档,正如Nofal Daud所说,Python错误是不言而喻的,如果dict上有keyror,就意味着字段不存在。下一次听Python,它将揭示真相。在
相关问题 更多 >
编程相关推荐