简体   繁体   中英

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. 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. 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

  • Get IP addresses from another place using requests

  • Compare Python arrays, dicts, tables or whatever format you got them

Unless more specific information about formats, tables, urls, etc. are included it is hard to give any detailed help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM