Changeset View
Changeset View
Standalone View
Standalone View
wallace/module_optout.py
Show First 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | |||||
def request(params=None): | def request(params=None): | ||||
params = json.dumps(params) | params = json.dumps(params) | ||||
optout_url = conf.get('wallace_optout', 'optout_url') | optout_url = conf.get('wallace_optout', 'optout_url') | ||||
try: | try: | ||||
f = urllib.urlopen(optout_url, params) | f = urllib.urlopen(optout_url, params) | ||||
except Exception, e: | except Exception: | ||||
log.error(_("Could not send request to optout_url %s") % (optout_url)) | log.error(_("Could not send request to optout_url %s") % (optout_url)) | ||||
return "DEFER" | return "DEFER" | ||||
response = f.read() | response = f.read() | ||||
try: | try: | ||||
response_data = json.loads(response) | response_data = json.loads(response) | ||||
except ValueError, e: | except ValueError: | ||||
# Some data is not JSON | # Some data is not JSON | ||||
print("Response data is not JSON") | print("Response data is not JSON") | ||||
return response_data['result'] | return response_data['result'] |