I use PhantomJSCloud to take screenshots of web apps. While writing new code, I noticed this error coming back from the server:
{
"name":"HttpStatusCodeException",
"statusCode":400,
"message":"Error extracting userRequest. innerException: JSON5: invalid character 'u' at 1:1",
"stack":[
"no stack unless env is DEV or TEST, or logLevel is DEBUG or TRACE"
]
}
The problem came because the request wasn’t JSON-encoding the object; the fix looks like this (using the requests library):
post_data_string = json.dumps(python_object_here, sort_keys=True, indent=3, separators=(',', ': '))
r = requests.post('https://phantomjscloud.com/api/browser/v2/', data=post_data_string)