python:接口间数据传递与调用方法

yipeiwu_com5年前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()
 

以上这篇python:接口间数据传递与调用方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python把数组中的数字每行打印3个并保存在文档中的方法

python把数组中的数字每行打印3个并保存在文档中的方法

如下所示: arrs=[2,15,48,4,5,6,7,6,4,1,2,3,6,6,7,4,6,8] f=open('test.txt','w+') count=0 for temp...

python实现感知机线性分类模型示例代码

python实现感知机线性分类模型示例代码

前言 感知器是分类的线性分类模型,其中输入为实例的特征向量,输出为实例的类别,取+1或-1的值作为正类或负类。感知器对应于输入空间中对输入特征进行分类的超平面,属于判别模型。 通过梯度...

详解通过API管理或定制开发ECS实例

弹性管理 ECS 实例 获取 RAM 子账号 AK 密钥 使用API管理ECS实例,您需要能访问ECS资源的API密钥(AccessKey ID 和 AccessKey Secret)...

对python:print打印时加u的含义详解

u:表示unicode字符串 不是仅仅是针对中文, 可以针对任何的字符串,代表是对字符串进行unicode编码。 一般英文字符在使用各种编码下, 基本都可以正常解析, 所以一般不带u;...

实例探究Python以并发方式编写高性能端口扫描器的方法

关于端口扫描器 端口扫描工具(Port Scanner)指用于探测服务器或主机开放端口情况的工具。常被计算机管理员用于确认安全策略,同时被攻击者用于识别目标主机上的可运作的网络服务。 端...