python接口自动化httpUtils
Posted zipon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python接口自动化httpUtils相关的知识,希望对你有一定的参考价值。
# coding=utf8 import requests from common.logger import Logger import logging class httpUtils: logger = Logger("../logs/http.log",logging.INFO,logging.INFO) def get(self,url,params={},headers={}): res = requests.get(url,data=params,headers=headers) self.logger.info("请求路径:" + res.request.url) headerStr = "" for headerKey in res.request.headers: headerStr = headerStr + "\n" + headerKey + ":" + res.request.headers[headerKey] self.logger.info("请求头信息:" + headerStr) self.logger.info("请求参数:\n" + res.request.body) resHeaderStr = "" for resHeaderKey in res.headers: resHeaderStr = resHeaderStr + "\n" + resHeaderKey + ":" + res.headers[resHeaderKey] self.logger.info("响应头信息:" + resHeaderStr) self.logger.info("返回结果:\n" + res.content.decode("utf-8")) return res def post(self,url,params={},headers={}): res = requests.post(url,data=params,headers=headers) self.logger.info("请求路径:"+res.request.url) headerStr = "" for headerKey in res.request.headers: headerStr =headerStr+ "\n" + headerKey + ":" + res.request.headers[headerKey] self.logger.info("请求头信息:" + headerStr) self.logger.info("请求参数:\n"+res.request.body) resHeaderStr = "" for resHeaderKey in res.headers: resHeaderStr =resHeaderStr+ "\n" + resHeaderKey + ":" + res.headers[resHeaderKey] self.logger.info("响应头信息:"+resHeaderStr) self.logger.info("返回结果:\n"+res.content.decode("utf-8")) return res
以上是关于python接口自动化httpUtils的主要内容,如果未能解决你的问题,请参考以下文章
Dynamics365 Sandbox中部署Plugin不支持HttpUtility.UrlEncode
Dynamics365 Sandbox中部署Plugin不支持HttpUtility.UrlEncode