您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
小编给大家分享一下如何搭建Pthon接口测试环境,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
环境搭建
python 安装:建议使用python3.7
pycharm安装
requests安装 :pip3 install requests
requests 基本使用
usage: >>> import requests >>> r = requests.get('https://www.python.org') >>> r.status_code 200 >>> 'Python is a programming language' in r.content True ... or POST: >>> payload = dict(key1='value1', key2='value2') >>> r = requests.post('https://httpbin.org/post', data=payload) >>> print(r.text) { ... "form": { "key2": "value2", "key1": "value1" }, ... }
获取返回数据:
res = requests.post(url,data).text 返回的是text格式 res = requests.post(url,data).json 返回的是json格式 requests上传文件的例子: import requests import json #上传文件 #url = 'https://www.imooc.com/user/postpic' download_url = 'http://file.mukewang.com/imoocweb/webroot/mobile/imooc7.2.010102001android.apk' file = { "fileField":("test.jpg",open("E:/ytxu/test.jpg","rb"),"image/jpg"), "type":"1" } cookie = { "apsid":"I5ZTVmZmUzMGE1NDY2OTljZjFjYzkyMTMyMjk3MmUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANzIxMzU2MQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABNdXNoaXNoaV94dUAxNjMuY29tAAAAAAAAAAAAAAAAADVjZDY5ZWYxMGQ2MmFlZDVmNTJkYWQ0ZWNhNjU5MjZhz%2BMFXc%2FjBV0%3DZW" } res = requests.get(download_url) with open("mukewang.apk","wb") as f: f.write(res.content) #res = requests.post(url,files=file,cookies=cookie,verify=False).json() print(res) #res = requests.post(url,files=file,cookies=cookie,verify=False).json() print(res)
requests 下载apk文件
requests 中 hearder介绍
requests hearder加密
flask环境搭建及简单开发
接口开发:
#coding=utf-8 import requests import json from flask import Flask app = Flask(__name__) @app.route("/") def logine(): data = json.dump( { 'username': "aa", 'password': "111111" } ) return data if __name__ == "__main__": app.run()
看完了这篇文章,相信你对如何搭建Pthon接口测试环境有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。