Skip to main content

紫鸟开放接口

Project description

sdk-python

安装

pip install requests

pip install rsa

Crypto安装

1.pip install pycryptodome

2.python安装路径下找到文件夹\Lib\site-packages\crypto, 将crypto重命名为Crypto

biz_model和params_model使用场景:

GET请求 使用biz_model 如:rpa_tasks_results_get.py POST、 PUT、DELETE请求: Body参数 使用biz_model 如:rpa_plans_post.py Query参数 使用params_model 如:rpa_plans_drivers_post.py, rpa_plans_drivers_delete.py

2023.5.16

更新OpenClient.py、RequestTypes.py、BaseRequest.py。 支持流式接口调用

2022.5.26

更新OpenClient.py、RequestTypes.py、BaseRequest.py。 通过参数params_model = {}设置url携带参数(GET请求以外有效)

接口封装步骤

比如查询计划详情接口

  • 接口名:/rpa/plans
  • 参数:planId 要查询的计划Id
  • 返回信息
{
        "msg": "SUCCESS",
        "code": "0",
        "data": {
            "name": "任务名称repeat",
            "platformId": "0",
            "actionType": "REPEAT_BY_WEEK"
        },
        "requestId": "765656",
}

针对这个接口,封装步骤如下:

1.在model包下新建一个类,定义业务参数

class RpaPlansGetModel:
    """查询计划详情"""

    # 要查询的计划Id
    planId = None

2.在request包下新建一个请求类,继承BaseRequest

重写get_method()方法,填接口名。

重写get_request_type()方法,填接口请求方式。

class RpaPlansGetRequest(BaseRequest):
    """查询计划详情"""

    def __init__(self):
        BaseRequest.__init__(self)

    def get_method(self):
        return '/rpa/plans'

    def get_request_type(self):
        return RequestTypes.GET

3.调用方式

    
# 自用API-查询计划详情
def rpa_plans_get():
    # 创建请求客户端
    client = OpenClient(Config.app_id, Config.private_key, Config.url)

    # 创建请求
    request = RpaPlansGetRequest()
    # 请求参数,方式一
    model = RpaPlansGetModel()
    model.planId = 5070
    request.biz_model = JsonUtil.to_json_string(model)
    # 请求参数,方式二
    # request.biz_model = {
    #     'planId': 5070
    # }

    # 调用请求
    response = client.execute(request, user_token='填写user_token')

    if response.is_success():
        print('response: ', response)
        print('data: ', response.data)
    else:
        print("response: ", response)
        print('请求失败,request_id:%s, code:%s, msg:%s, sub_code:%s, sub_msg:%s' % \
              (response.request_id, response.code, response.msg, response.sub_code, response.sub_msg))

流式接口调用方式

        # 调用请求,设置stream=True
        response = client.execute(request, app_token='填写app_token', stream=True)
        # 迭代获取流结果
        for item in response.iter_content():
            if item.is_success():
                print(item.get_content())
                print(item.data)
            else:
                print('请求失败,request_id:%s, code:%s, msg:%s, sub_code:%s, sub_msg:%s' %
                      (item.request_id, item.code, item.msg, item.sub_code, item.sub_msg))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ziniao_oapi-0.1.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ziniao_oapi-0.1.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file ziniao_oapi-0.1.1.tar.gz.

File metadata

  • Download URL: ziniao_oapi-0.1.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Windows/11

File hashes

Hashes for ziniao_oapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 711365a567301b1b46f0e7aebc7ab28b45a67987a97932bd5d937f585619e4cb
MD5 4080ebc39c71d3d6029c0e759f6792e7
BLAKE2b-256 e96a90240e89050b9521d5863c181c67079dac17139412ec899546a5852620b6

See more details on using hashes here.

File details

Details for the file ziniao_oapi-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ziniao_oapi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Windows/11

File hashes

Hashes for ziniao_oapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1ff4f704d9c94418bb73fffb5e77725ecc0ae356d6846667a7a7dbda9ce3642
MD5 30a769d3aedbf16e0933d242a254fa6b
BLAKE2b-256 5e98e45cb9f55b120fc90ddb5c3dbf5d439ab4fcdd826abcc6d17bd53839d50c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page