python requests post請求時提示“ expect {, actual ident, pos 0"”
阿新 • • 發佈:2022-05-06
請求時提示:{"content":null,"errorCode":"000001","errorMsg":"syntax error, expect {, actual ident, pos 0","status":"ERROR"}按照下面備註處理即可
def run_main(self, method=None, url=None, data=None,headers=None): result = None if method == 'POST': ''' 因為我請求的系統請求頭中有Content-Type: application/json;charset=UTF-8, 所以data需要轉化為json,所以需要加上data=json.dumps(data),不然會提示錯誤,如果是其它請求頭則不需要 ''' result = requests.post(url=url,data=json.dumps(data),headers=headers) elif method == 'GET': result = requests.get(url=url, data=json.dumps(data), headers=headers) elif method == 'PUT': result = requests.PUT(url=url, data=json.dumps(data), headers=headers) elif method == 'DELETE': result = requests.DELETE(url=url, data=json.dumps(data), headers=headers) else: print("錯誤") return result```