java调用python接口、传参json对象-python:接口间数据传递与调用方法

import requests

import unittest

import json

from pubulic_way.get_token import getSession

class testlogin(unittest.TestCase):

def test_getIdentify(self):

"""调用test_listCollectInfoByCreditId(self)响应数据中的taxid参数"""

result = self.get_listCollectInfoByCreditId()

json_result=json.loads(result)

p1 = json_result["polygons"][0]["ENTERPRISETAXID"]

data = {"lyname":"COL_WPOLYGON_3206","id":"8f34969c-ea5e-489c-94bc-37e54ad40660","taxid":p1}

url = "http://10.17.17.31:8080/LandTaxSys/search/getLayerAlianame"

headers = {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}

cookies = self.get_cookies()

r = requests.post(url,data=data,headers=headers,cookies=cookies)

# print(p1)

# print(r.status_code)

# print(r.text)

# return r.text

checkpoint = "91320612MA1UYCL59U"

if r.status_code == 200:

if checkpoint in r.text:

print("测试结果:Passed,断言成功。响应状态码:{}。响应数据【json】:{}".format(r.status_code,r.text))

else:

print("测试结果:Failed,断言失败。响应状态码:{}。断言内容为:{}。响应数据【json】:{}".format(r.status_code,checkpoint,r.text))

else:

print("测试结果:Failed,接口不通。响应状态码:{}。响应数据【json】:{}".format(r.status_code,r.text))

def get_listCollectInfoByCreditId(self):

"""获取响应数据中的taxid参数"""

url = "http://10.17.17.31:8080/LandTaxSys/dataEdit/listCollectInfoByCreditId"

data = {"start":"1","end":"8","targetTaxId":"91320612MA1UYCL59U","nearbyTaxId":"","swjgDm":"23206","userId":"32060100033"}

headers = {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}

cookies = self.get_cookies()

r = requests.post(url,data=data,headers=headers,cookies=cookies)

return r.text

def get_cookies(self):

cookies = getSession()

return cookies

if __name__ == "__main__":

unittest.main()

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值