接口测试报错 求解?


import unittest

import json

from demo import RunMain


class TestMethod(unittest.TestCase):


def setUp(self):

self.run=RunMain()


def test_01(self):

url='http://api-app.meizu.com/apps/public/category/layout'

data={

"custom_icon":"1",

"device_model":"M57AC",

"firmware":"Flyme OS 5.1.0.6QY",

"imei":"868905020250933",

"language":"zh-CN",

"locale":"CN",

"max":"50",

"mpv":"appsv5",

"mzos":"5",

"net":"wifi",

"os":"22",

"screen_size":"1080x1920",

"sn":"A1CEBN3223GS",

"start":"0",

"v":"5.0.8",

"vc":"210"

}


# run=RunMain()


res=self.run.run_main(url,'POST',data)

print res


def test_02(self):

url='http://api-app.meizu.com/apps/public/category/layout'

data={

"custom_icon":"1",

"device_model":"M57AC",

"firmware":"Flyme OS 5.1.0.6QY",

"imei":"868905020250934",

"language":"zh-CN",

"locale":"CN",

"max":"50",

"mpv":"appsv5",

"mzos":"5",

"net":"wifi",

"os":"22",

"screen_size":"1080x1920",

"sn":"A1CEBN3223GS",

"start":"0",

"v":"5.0.8",

"vc":"210"

}


res=self.run.run_main(url,'POST',data)

print res


if __name__ == '__main__':

unittest.main()

——————————————————————————————————————————————

#coding=utf-8

import json

import requests



class RunMain:


def __init__(self,url,method,data=None):

self.res=self.run_main(url,method,data)


def send_get(self,url,data):

res=requests.get(url=url,data=data).json()

return json.dumps(res,indent=2,sort_keys=True)



def send_post(self,url,data):

res=requests.post(url=url,data=data).json()

return json.dumps(res,indent=2,sort_keys=True)


def run_main(self,url,method,data=None):

res=None

if method=='GET':

res=self.send_get(url,data)

else:

res=self.send_post(url,data)

return res


if __name__ == '__main__':


url='http://api-app.meizu.com/apps/public/category/layout'

data={

"custom_icon":"1",

"device_model":"M57AC",

"firmware":"Flyme OS 5.1.0.6QY",

"imei":"868905020250933",

"language":"zh-CN",

"locale":"CN",

"max":"50",

"mpv":"appsv5",

"mzos":"5",

"net":"wifi",

"os":"22",

"screen_size":"1080x1920",

"sn":"A1CEBN3223GS",

"start":"0",

"v":"5.0.8",

"vc":"210"

}

run=RunMain(url,'POST',data)

print run.res

# print run.run_main(url,'POST',data)



https://img2.mukewang.com/5d2c9b790001c85807910417.jpg

aimike
浏览 978回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP