SuperAPI AI 工具集

telnyx-seti-python

编程与开发

查看项目

更新于 10-16 05:29

技能介绍

用途

Telnyx SETI Python 是一个 Python 技能包,用于访问 SETI(Space Exploration Telecommunications Infrastructure,太空探索电信基础设施)API。该技能以 Python SDK 示例的形式,帮助开发者在 Python 项目中调用 Telnyx 提供的相关接口。

安装与初始化

安装命令:

pip install telnyx

初始化客户端:

import os
from telnyx import Telnyx

client = Telnyx(
    api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
)

后续所有示例均假设 client 已按上述方式初始化。

主要能力

错误处理

所有 API 调用都可能因网络错误、速率限制(429)、验证错误(422)或认证错误(401)而失败。生产代码中应始终处理错误:

import telnyx

try:
    result = client.messages.send(to="+13125550001", from_="+13125550002", text="Hello")
except telnyx.APIConnectionError:
    print("Network error — check connectivity and retry")
except telnyx.RateLimitError:
    # 429: rate limited — wait and retry with exponential backoff
    import time
    time.sleep(1)  # Check Retry-After header for actual delay
except telnyx.APIStatusError as e:
    print(f"API error {e.status_code}: {e.message}")
    if e.status_code == 422:
        print("Validation error — check required fields and formats")

常见错误码:401 表示 API 密钥无效,403 表示权限不足,404 表示资源未找到,422 表示验证错误(需检查字段格式),429 表示触发速率限制(建议使用指数退避重试)。

获取枚举

接口:GET /10dlc/enum/{endpoint}

response = client.messaging_10dlc.get_enum(
    "mno",
)
print(response)

检索黑盒测试结果

返回各类黑盒测试的结果。

接口:GET /seti/black_box_test_results

response = client.seti.retrieve_black_box_test_results()
print(response.data)

返回字段包括:black_box_tests(array[object])、product(string)、record_type(string)。

使用方式

  1. 通过 pip 安装 telnyx 包。
  2. 使用 TELNYX_API_KEY 环境变量初始化 Telnyx 客户端。
  3. 按需调用 client.messaging_10dlc.get_enum、client.seti.retrieve_black_box_test_results 等方法。
  4. 在生产代码中捕获并处理 APIConnectionError、RateLimitError、APIStatusError 等异常。

适用场景

适用于需要在 Python 项目中集成 Telnyx SETI 电信基础设施 API 的开发者,尤其是涉及 10DLC 枚举查询、SETI 黑盒测试结果获取以及消息发送等场景。

限制

关于该技能的收费、价格、平台支持范围、性能效果等具体信息,资料中暂未提供。