TypeError: the JSON object must be str, not 'bytes'报错问题解决
def basic_information_new_customer(url,jobMonthlyIncome,occupation,applyTime,age,personalAddress,jobCompanyAddress): #规则集调用 url = url+"/api/invokeRule" data = { "sysCode": "urule_india", "frontTransNo": "id00011", "frontTransTime": "2019-05-29 00:00:00", "rulePackage": "PERSONAL_INFO", "requestBody":{ "PersonalInfoDTO": { "jobMonthlyIncome": jobMonthlyIncome,#个人信息-月工资 "occupation": occupation,#个人信息-职业 "applyTime": applyTime,#个人信息-申请时间 "age": age,#基本信息-年龄 "personalAddress": personalAddress,#个人信息-申请人居住省份/邦 "jobCompanyAddress": jobCompanyAddress#个人信息-申请人工作省份/邦 } } } headers = {"Content-Type": "application/json"} req = requests.post(url=url, data=json.dumps(data), headers=headers) res = json.loads(req.content.decode()) #.decode() #print(type(res)) #loads 输出的是 dict类型 return res
解决方法:
直接添加decode()解决
decode() 方法以 encoding 指定的编码格式解码字符串。该方法返回解码后即为字符串。
decode()方法语法:str.decode(encoding='UTF-8',errors='strict')
一切技术都是为业务服务,脱离业务的技术一文不值!