python推送app_服务端(python)推送消息(一) 基本配置

兼容版本

Python 2.7

Python 3

环境配置

pip 方式:

sudo pip install jpush

代码样例

代码样例在 jpush-api-python-client 中的 examples 文件夹中,点击查看所有 examples。

以下片断来自项目代码里的文件:jpush-api-python-client 中的 examples/push_examples 目录下的 example_all.py

这个样例演示了消息推送,日志设置,异常处理。

_jpush = jpush.JPush(app_key, master_secret)

push = _jpush.create_push()

# if you set the logging level to "DEBUG",it will show the debug logging.

_jpush.set_logging("DEBUG")

push.audience = jpush.all_

push.notification = jpush.notification(alert="hello python jpush api")

push.platform = jpush.all_

try:

response=push.send()

except common.Unauthorized:

raise common.Unauthorized("Unauthorized")

except common.APIConnectionException:

raise common.APIConnectionException("conn error")

except common.JPushFailure:

print ("JPushFailure")

except:

print ("Exception")

日志说明

logging level 默认的是 WARNING ,为了方便调试建议设置为 DEBUG 设置方法为:

_jpush.set_logging("DEBUG")

异常说明

Unauthorized

AppKey,Master Secret 错误,验证失败必须改正。

APIConnectionException

包含错误的信息:比如超时,无网络等情况。

JPushFailure

请求出错,参考业务返回码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值