Python Curl Command

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.