---
# System prepended metadata

title: '[PYTHON] 連動 LINE'
tags: [告警, python, LINE, NOTIFY, ALERT]

---

# PYTHON 連動 LINE


1. 建立一個line群組
1. 把LINE Notify這個帳號加入群組(以及其它要接收通知的人)
1. 登入[https://notify-bot.line.me/zh_TW/](https://notify-bot.line.me/zh_TW/) 頁面
1. 發行權杖(權杖名稱為發送訊息時【】裡的字)
1. 將產生的token記下，寫在程式碼內

參考網址：
https://bustlec.github.io/note/2018/07/10/line-notify-using-python/


```python=
import requests

def lineNotifyMessage(token, msg):
    headers = {
        "Authorization": "Bearer " + token, 
        "Content-Type" : "application/x-www-form-urlencoded"
    }
    payload = {'message': msg}
    r = requests.post("https://notify-api.line.me/api/notify", headers = headers, params = payload)
    return r.status_code
	
# 修改為你要傳送的訊息內容
message = 'Notify from LINE, 中文測試'
# 修改為你的權杖內容
token = 'xxxxxxxxxxxxgggggggggooooooppppp'

lineNotifyMessage(token, message)
```


###### tags: `python` `LINE` `NOTIFY` `ALERT` `告警`