神剑山庄资源网 Design By www.hcban.com

环境搭建

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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
Python,接口测试,环境搭建

神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com

评论“Python接口测试环境搭建过程详解”

暂无Python接口测试环境搭建过程详解的评论...