I am trying to finish this script but I am having an issue with the exception handling. I get that it is try, except, else but I guess I am confused on what I need to put within this statement to make it function as it needs to while also pulling out the country code from JSON returned. It appears that my code works, I am just stuck on getting this part finished. Any help is welcomed!
import requests #API Key left blank key = #function used to lookup the appropriate country code def getCountry(ip): apiURL = 'https://atlas.microsoft.com/geolocation/ip/json?subscription-key=' print(r.json()) #Exception handling to avoid errors that may prevent all IPs from being processed #Need to extract the country code from the JSON returned for ip in r.json: try: def main(): print("Good Luck") print(getCountry('8.8.8.8)) if _name_ == "_main_": main() https://stackoverflow.com/questions/67051831/exception-handling-within-an-api-pull-while-extracting-country-code-from-json-re April 12, 2021 at 10:05AM
没有评论:
发表评论