简体   繁体   English

使用python如何同时连接到两个不同的api,以便可以比较数据?

[英]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.

相关问题 如何使用python比较两个不同的csv文件? - How can I compare two different csv file using python? 如何修复我的 Pandas 代码,以便正确比较来自两个不同时间点的观察结果? - How can I fix my pandas code so that it will correctly compare observations from two different points in time? How do I stream data from two different web sockets at the same time using the websocket.WebsocketApp in python? - How do I stream data from two different web sockets at the same time using the websocket.WebsocketApp in python? 如何同时在 Python 中运行两个不同的代码? - How can I run two different code in Python at the same time? 我如何寻求同时比较不同数据框中的两列? - how do i seek to compare two columns in different dataframes at the same time? 我如何比较python中两行不同的两列 - How can i compare two columns in two different rows in python 我如何基于相同的ID比较两个不同数据框中的日期列 - how do i compare date columns in two different data frames based on the same ID 如何比较两个不同长度的Python Pandas系列? - How do I compare two Python Pandas Series of different lengths? 如何从数据集中调用并让它比较 python 中的两个不同数据点? - How do I call from a dataset and have it compare two different data points in python? 如何在Python中比较两个不同类型的日期? - How can I compare two dates of different types in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM