Demo entry 2530714

Simple python class

   

Submitted by anonymous on Aug 27, 2015 at 12:59
Language: Python 3. Code size: 642 Bytes.

#!/usr/bin/env python

import sys,re,os,calendar,json
import requests #pip install requests if you don't have it already

URL = "http://localhost:8000"

qrp = sys.argv[1]

url = '%s/try/%s' % (URL,qrp)

r = requests.get(url)
try:
    status = r.json()['status']
except ValueError:
    print("*** Error(%s): Stage 1. Unknown response data - not json. Status code: %s" % (qrp,r.status_code))
    sys.exit(1)

if status == 'error':
    print("*** Error(%s): Stage 1. %s" % (qrp,r.json()['error']))
    sys.exit(1)

if status != 'ok':
    print("*** Error(%s): Stage 1. Unknown status %s" % (qrp,status))
    sys.exit(1)

print("ok")
sys.exit(0)

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).