[英]Using python how do I connect to two different api s at the same time so I can compare data?
I am using the requests and json modules. 我正在使用请求和json模块。 So my current code looks like.
所以我当前的代码看起来像。
# API url to connect
url1 = url
url2 = url
# Authentication for Url1, Url2 doesn't need auth
usr = username
pass = password
r2 = requests.get(url1, auth=(usr, pass), verify=False)
r3 = requests.get(url2, verify=False)
for obj in json.loads(r2.text)['results']:
for obj in json.loads(r3.text)['ip']:
if str(obj['ip']) == str(obj['ip']):
print "Hostname: " + str(obj['name']) + ", IP: " + str(obj['ip'])
What I need to do now is add another api to this mix and I want to run an if statement that compares ip addresses to make sure that our servers on one reporting system can cross reference itself to another system that is manually entered. 我现在需要做的是向此混合添加另一个api,我想运行一个if语句来比较ip地址,以确保我们在一个报告系统上的服务器可以交叉引用到另一个手动输入的系统。 So we can know what is in there or not.
这样我们就可以知道里面有什么。 Sorry for the poor example I'm on my train ride home and seriously am stuck.
对不起,这个可怜的例子很抱歉,我在回家的火车上被严重卡住了。
This question lacks details to be answerable. 这个问题缺少细节要回答。 Do it like this
像这样做
Get IP addresses from one place using requests 使用请求从一个地方获取IP地址
Get IP addresses from another place using requests 使用请求从另一个地方获取IP地址
Compare Python arrays, dicts, tables or whatever format you got them 比较Python数组,字典,表格或您获得的任何格式
Unless more specific information about formats, tables, urls, etc. are included it is hard to give any detailed help. 除非包含有关格式,表,URL等的更具体的信息,否则很难提供任何详细的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.