Python脚本接口返回正常,状态码405

最近些Python接口脚本时调用post接口时返回结果正常,状态码却不对。

 

 ,代码如下:

 

 此接口完成的功能为新增一个角色,角色添加成功返回角色的id信息,但是状态码为405,405是Method Not Allowed 客户端请求中的方法被禁止,网上查一堆405解决方法都对不上原因。后向开发请教,一般这种情况为post用成了get,查看上面脚本发现,

r = requests.get(url=self._url, data=self._data, headers=header)
status = r.status_code
print('Status Code:', status)

获取接口状态码这里post用成了get,改为

r = requests.post(url=self._url, data=self._data, headers=header)
status = r.status_code
print('Status Code:', status)

状态码变为200。

posted @ 2021-03-05 14:54  负重前行,前方更好  阅读(2336)  评论(0)    收藏  举报