关于requests.post().json()获取到的JSON为单引号和NONE的那些事

上篇学习sys.argv的使用代码中发现了错误,获取到的Json数据为单引号和NONE,为错误的json格式。

经检查,发现直接使用r.text就可以得到正确的json数组,使用r.json()反而使json数组中的双引号变为单引号,null变为NONE。

之后进行cmd调试的时候发现无法获取OrderEventForCT中的数据,经过一通我也没有找到原因的操作后,cmd页面可以通过sys.argv显示数据。

修改后代码如下

import requests
import sys

url = 'http://www.700156.com/CT/Order/DataQueryNew'


def query(companyid, he_type, he_no):
    d = {'companyid': companyid, 'type': he_type, 'no': he_no}
    r = requests.post(url, data=d)
    return r.text


if __name__ == '__main__':
    company_id = sys.argv[1]
    the_type = sys.argv[2]
    the_no = sys.argv[3]
    print(query(company_id, the_type, the_no))
    # print(query("CT56", 1, "8039593329"))
原文地址:https://www.cnblogs.com/fwjlucifinil/p/13234772.html