This afternoon came, ran the Curl-i Url:port, and then returned the information, with the json.loads () parsing, to report a mistake:
Traceback (most recent):
File "test1.py", line A, in <module>
Decodejson = json.loads (str1)
File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
return _default_decoder.decode (s)
File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
obj, end = Self.raw_decode (S, idx=_w (s, 0). End ())
File "/usr/lib/python3.4/json/decoder.py", line 361, in Raw_decode
Raise ValueError (ErrMsg ("Expecting value", S, Err.value)) from None
Valueerror:expecting value:line 1 column 1 (char 0)
Test 1: The original thought that Python could not parse the JSON null, try to change the JSON null to other strings, found or reported this error .... Later, loads () can convert the JSON null to none. No problem!
Test 2: It was later suspected that the string passed by OPS was not in JSON format. Use the eval () function to determine the return data type, judging by the way:
try: eval(jsonStr)except Exception,e :
print"不是json字符串"
Found that the suspicion is justified! , it is not JSON, step by step to go up;
Test 3: Since it is not JSON, there is either a problem with the background data, or the command I picked is incorrect. And the people in the background to test, found that: Sure enough is the problem of Curl command .....
Curl-i XXXXX Returns the contents of the entire HTTP ... Include request lines. The request body. Request Header ...
And Curl XXXX returns only the HTTP request body ...
Summarize: 1, write code, must write a logical judgment, or try. Catch.. Otherwise the bug is really hard to find.
2, have time to look at curl, a powerful pen Ah!
Python Curl Command