Package: 51tracking
51tracking-sdk-pythonThe Python SDK of 51Tracking APIContact:service@51tracking.orgOfficial documentDocumentSupported Python Versions3.63.73.83.93.10pypy3IndexInstallationTestingError HandlingSDKCouriersTrackingsAir WaybillInstallation$ pip install 51trackingVia source code下载代码压缩包，无需解压缩，进入源代码根目录，然后运行：$ pip install 51tracking-sdk-python.zipQuick Startimporttracking51tracking51.api_key='you api key'try:couriers=tracking51.courier.get_all_couriers()print(couriers)excepttracking51.exception.Tracking51Exceptionasce:print(ce)exceptExceptionase:print("other error:",e)TestingpytestError handlingThrowby the new SDK clientimporttracking51tracking51.api_key=''try:couriers=tracking51.courier.get_all_couriers()print(couriers)excepttracking51.exception.Tracking51Exceptionasce:print(ce)# API Key is missingThrowby the parameter validation in functionimporttracking51tracking51.api_key='you api key'try:params={'tracking_number':'','courier_code':'usps'}result=tracking51.tracking.create_tracking(params)print(result)excepttracking51.exception.Tracking51Exceptionasce:print(ce)# Tracking number cannot be emptyExamplesCouriers返回所有支持的快递公司列表https://api.51Tracking.com/v4/couriers/alltry:result=tracking51.courier.get_all_couriers()print(result)excepttracking51.exception.Tracking51Exceptionasce:print(ce)exceptExceptionase:print("other error:",e)Trackings单个物流单号实时添加且查询https://api.51Tracking.com/v4/trackings/createtry:params={'tracking_number':'92612903029511573030094547','courier_code':'usps'}result=tracking51.tracking.create_tracking(params)print(result)excepttracking51.exception.Tracking51Exceptionasce:print(ce)exceptExceptionase:print("other error:",e)获取多个物流单号的查询结果https://api.51Tracking.com/v4/trackings/gettry:# Perform queries based on various conditions# params = {'tracking_numbers': '92612903029511573030094547', 'courier_code': 'usps'}# params = {'tracking_numbers': '92612903029511573030094547,92612903029511573030094548', 'courier_code': 'usps'}params={'created_date_min':'2023-08-23T14:00:00+00:00','created_date_max':'2023-08-23T15:04:00+00:00'}result=tracking51.tracking.get_tracking_results(params)print(result)excepttracking51.exception.Tracking51Exceptionasce:print(ce)exceptExceptionase:print("other error:",e)添加多个物流单号（一次调用最多创建 40 个物流单号）https://api.51Tracking.com/v4/trackings/batchtry:params=[{'tracking_number':'92612903029511573030094593','courier_code':'usps'},{'tracking_number':'92612903029511573030094594','courier_code':'usps'}]result=tracking51.tracking.batch_create_trackings(params)print(result)excepttracking51.exception.Tracking51Exceptionasce:print(ce)exceptExceptionase:print("other error:",e)根据ID更新物流信息https://api.51Tracking.com/v4/trackings/update/{id}params={'customer_name':'New name','note':'New tests order note'}id_string="9a2f732e29b5ed2071d4cf6b5f4a3d19"try:result=tracking51.tracking.update_tracking_by_id(id_string,params)print(result)excepttracking51.exception.Tracking51Exceptionasce:print(ce)exceptExceptionase:print("other error:",e)通过ID删除单号https://api.51Tracking.com/v4/trackings/delete/{id}id_string="9a2f7d1e8b912b729388c5835c188c28"try:result=tracking51.tracking.batch_create_trackings(params)print(result)excepttracking51.exception.Tracking51Exceptionasce:print(ce)exceptExceptionase:print("other error:",e)通过ID重新查询过期的单号https://api.51Tracking.com/v4/trackings/retrack/{id}id_string="9a2f7d1e8b912b729388c5835c188c28"try:result=tracking51.tracking.retrack_tracking_by_id(id_string)print(result)excepttracking51.exception.Tracking51Exceptionasce:print(ce)exceptExceptionase:print("other error:",e)Air Waybill查询航空运单的结果https://api.51Tracking.com/v4/awbparams={'awb_number':'235-69030430'}try:result=tracking51.air_waybill.create_an_air_waybill(params)print(result)excepttracking51.exception.Tracking51Exceptionasce:print(ce)exceptExceptionase:print("other error:",e)响应状态码51Tracking 使用传统的HTTP状态码来表明 API 请求的状态。通常，2xx形式的状态码表示请求成功，4XX形式的状态码表请求发生错误（比如：必要参数缺失），5xx格式的状态码表示 51tracking 的服务器可能发生了问题。Http CODEMETA CODETYPEMESSAGE200200成功请求响应成功。400400错误请求请求类型错误。请查看 API 文档以了解此 API 的请求类型。4004101错误请求物流单号已存在。4004102错误请求物流单号不存在。请先使用「Create接口」将单号添加至系统。4004103错误请求您已超出 API 调用的创建数量。每次创建的最大数量为 40 个快递单号。4004110错误请求物流单号(tracking_number) 不符合规则。4004111错误请求物流单号(tracking_number)为必填字段。4004112错误请求查询ID无效。4004113错误请求不允许重新查询。您只能重新查询过期的物流单号。4004120错误请求物流商简码(courier_code)的值无效。4004121错误请求无法识别物流商。4004122错误请求特殊物流商字段缺失或填写不符合规范。4004130错误请求请求参数的格式无效。4004160错误请求空运单号(awb_number)是必需的或有效的格式。4004161错误请求此空运航空不支持查询。4004165错误请求查询失败：未创建空运单号。4004166错误请求删除未创建的空运单号失败。4004167错误请求空运单号已存在，无需再次创建。4004190错误请求当前查询额度不足。401401未经授权身份验证失败或没有权限。请检查并确保您的 API 密钥正确无误。403403禁止禁止访问。请求被拒绝或不允许访问。404404未找到页面不存在。请检查并确保您的链接正确无误。429429太多请求超出 API 请求限制，请稍后重试。请查看 API 文档以了解此 API 的限制。500511服务器错误服务器错误。请联系我们：service@51Tracking.org。500512服务器错误服务器错误。请联系我们：service@51Tracking.org。500513服务器错误服务器错误。请联系我们：service@51Tracking.org。