Created
March 22, 2018 15:50
-
-
Save maxyko/997a38d9f60387b49284102ee11d73d0 to your computer and use it in GitHub Desktop.
temp_file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ssl | |
import urllib2 | |
import urllib | |
import logging | |
import json | |
import sys | |
logger = logging.getLogger(__name__) | |
logger.addHandler(logging.NullHandler) | |
def parser(argument): | |
response = get_url("http://localhost/a-/readinessXXX", secure=False) | |
print response.getcode() | |
if response.getcode() == 200: | |
print 'Its OK' | |
try: | |
values = json.load(response) | |
except: | |
print "Its NOT JSON format" | |
try: | |
if values[argument]['status'] == 'ok': | |
print '1' | |
else: | |
print '0' | |
except KeyError: | |
print "Wrong parameter!!!" | |
def get_url(url, data=None, secure=True): | |
try: | |
context = ssl.create_default_context() | |
if not secure: | |
context.check_hostname = False | |
context.verify_mode = ssl.CERT_NONE | |
ret = urllib2.urlopen(url, data=data, context=context) | |
return ret | |
except: | |
logging.exception("Sorry, something went wrong retrieving url {}".format(url)) | |
raise | |
if __name__ == "__main__": | |
parser(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment