用于python异步的expo sdk服务器
aioexponent的Python项目详细描述
所有组件
如果您对此存储库中的代码有问题,请提交问题或请求谢谢!
安装
pip install aioexponent
用法
用于从Python服务器向指数体验发送推送通知
如果您想深入了解详细信息,可以使用API上的Full documentation
下面是一个示例,说明如何通过pyrollbar将其用于重试和报告
fromaioexponentimportDeviceNotRegisteredErrorfromaioexponentimportPushClientfromaioexponentimportPushMessagefromaioexponentimportPushResponseErrorfromaioexponentimportPushServerErrorfromaiohttpimportClientError# Basic arguments. You should extend this function with the push features you# want to use, or simply pass in a `PushMessage` object.asyncdefsend_push_message(tokens,message,extra=None):client=PushClient()try:response=awaitclient.publish_multiple([PushMessage(to=token,body=message,data=extra)fortokenintokens])exceptPushServerErrorasexc:# Encountered some likely formatting/validation error.rollbar.report_exc_info(extra_data={'tokens':tokens,'message':message,'extra':extra'errors':exc.errors,'response_data':exc.response_data,})raiseexcept(ClientError)asexc:# Encountered some Connection or HTTP error - retry a few times in# case it is transient.rollbar.report_exc_info(extra_data={'tokens':tokens,'message':message,'extra':extra})raiseretry(exc=exc)try:# We got a response back, but we don't know whether it's an error yet.# This call raises errors so we can handle them with normal exception# flows.response.validate_response()exceptDeviceNotRegisteredError:# Mark the push token as inactivefromnotifications.modelsimportPushTokenPushToken.objects.filter(token=token).update(active=False)exceptPushResponseErrorasexc:# Encountered some other per-notification error.rollbar.report_exc_info(extra_data={'tokens':tokens,'message':message,'extra':extra,'push_response':exc.push_response._asdict(),})raiseretry(exc=exc)