Created
February 7, 2018 08:53
-
-
Save PankajWorks/61f7c65963ad0cb594e225e5cfa0b420 to your computer and use it in GitHub Desktop.
convert to json
This file contains 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
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