Skip to content

Instantly share code, notes, and snippets.

@PankajWorks
Created February 7, 2018 08:53
Show Gist options
  • Save PankajWorks/61f7c65963ad0cb594e225e5cfa0b420 to your computer and use it in GitHub Desktop.
Save PankajWorks/61f7c65963ad0cb594e225e5cfa0b420 to your computer and use it in GitHub Desktop.
convert to json
def get_task_json_data(data,length=256):
try:
json_data = None
if data and len(data)>length:
return error(400, 'value is > expected characters i.e. %s' % length)
elif data and not isinstance(data,dict):
return error(400, 'value is not a dictonary/json: %s' % data)
elif data and isinstance(data,dict):
json_data = json.dumps(data)
status = 0
except ValueError:
logger.error(traceback.format_exc())
return 400, 'ValueError: %s' % traceback.format_exc()
except:
logger.error(traceback.format_exc())
return 500, "Unexpected error: %s" % traceback.format_exc()
return status, json_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment