程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] use pushplus to realize alert email reminder, and provide code and detailed comments

編輯:Python

Catalog

    • Running effect
    • How to get token Authorization code
    • How to bind mailboxes
      • 1. Open the personal Center
      • 2. Open your profile
      • 3. Click verify email
      • 4. Verify email
    • Run code
    • official API file
    • summary


Welcome to your attention 『 I found you far away 』 Blog , Ongoing update
Welcome to your attention 『 I found you far away 』 Blog , Ongoing update

Running effect


How to get token Authorization code

http://www.pushplus.plus/push1.html

You can scan the wechat code and log in to get token


How to bind mailboxes

1. Open the personal Center

2. Open your profile

3. Click verify email

4. Verify email


Run code

# @Time : 2022/6/21 8:33
# @Author : Nanli 
# @FileName: push Push send email reminder .py
import requests
import json
import time
token = ' Yours token' # stay pushpush You can find it on the website 
title= ' Data exception email warning reminder ' # Change to the title you want 
error_time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))# Get the formatted time 
error_dataType=' Gateway data '
error_number=404
# Pay attention , The content below is because json Why , Note the key value pairs '' Symbol 
# Format of the first character splicing type 
#content ="{' Exception data type ':' Gateway data ',' Time of exception ':'"+str(error_time)+"',' Exception error code ':'404'}" # Change to the text you want 
# The second kind ( recommend ) practical format Formatting 
content ="{"+"' Exception data type ':'{}',' Time of exception ':'{}',' Exception error code ':'{}'".format(error_dataType,str(error_time),error_number)+"}" # Change to the text you want 
data = {

"token":token,
"title":title,
"content":content,
"channel":"mail",# The point is , Represents a message 
"template":"json"
}
url = 'http://www.pushplus.plus/send/{}'.format(token)# Request here url There are changes 
body=json.dumps(data).encode(encoding='utf-8')
headers = {
'Content-Type':'application/json'}
request_result=requests.post(url,data=body,headers=headers)
print(request_result)# <Response [200]>
# The interface return code is described as follows :
#
# Return code explain 
# 200 Successful implementation 
# 302 Not logged in 
# 401 Request not authorized 
# 403 request IP unauthorized 
# 500 System exception , Please try again later 
# 600 Data exception , operation failed 
# 805 No permission to view 
# 888 Not enough points , Recharge required 
# 900 User account usage is restricted 
# 999 Server verification error 

official API file

This section is from http://www.pushplus.plus/doc/guide/api.html# One 、 Send message interface


summary

If you like , Give me one , Pay attention to ! Let's share more ways for computer majors to study !

Copyright notice :

I found you far away @mzh Original works , Reprint must be marked with the original link

Copyright 2022 mzh

Crated:2022-2-1

Welcome to your attention 『 I found you far away 』 Blog , Ongoing update
Welcome to your attention 『 I found you far away 』 Blog , Ongoing update



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved