我希望IP-API解析我在第一个链接中获得的IP,但它不起作用。
#!/usr/bin/python
import sys
import requests
print "Conectando com %s" % sys.argv[1]
Get_Skype = requests.get("http://api.predator.wtf/resolver/?arguments=%s" % sys.argv[1]).text
print "Entrando em %s" % Get_Skype
My_API = requests.get("http://ip-api.com/json/%s" % Get_Skype).text
print My_API
命令行:
$ python script.py user_skype
api返回:
{"message":"invalid query","query":"<ip>","status":"fail"}
请求的结果"http://api.predator.wtf/resolver/?arguments=user_skype"存储在Get_Skype
中的是
Crap,找不到IP!
而不是一个有效的IP,这会导致您的api认为它是一个糟糕的查询(实际上是这样)。因此,在将结果传递给API之前,您可能应该首先检查该结果是否为有效的IP地址。
如果输入了有效的用户名,则predator
查询的结果会有一个尾随的ufeff
字符,即BOM。请参阅如何处理它。