이번에는 파일 업로드를 해보겠습니다.
파일 업로드는 chat.postMessage API를 사용하지 않고 별도의 API를 사용합니다.
이번에도 헤더 부분 정의가 필요합니다.
Content-type이 application/json 이 아닙니다!
header = {'Content-type': 'application/x-www-form-urlencoded; charset=utf-8', 'Authorization': {slack 토큰}}
data로 보낼 attachments를 지정해줍니다.
이미지를 먼저 객체화 합니다.
with open({전송 이미지 경로}, 'rb') as f:
content = f.read()
그리고 이미지 데이터인 content를 data에 넣어줍니다.
attachments = {
"channels": {슬랙채널ID},
"thread_ts": {쓰레드일 경우 쓰레드ts},
"title": "error screentshot",
"content": content
}
그리고 전송!
requests.post('https://slack.com/api/files.upload', headers=header, data=attachments)
728x90
'Study > Python' 카테고리의 다른 글
sys.argv 로 명령줄 인수 사용하기 (0) | 2023.09.27 |
---|---|
technology ebooks. 다양한 언어와 기술 전자책이 있는 웹사이트 공유 (0) | 2023.05.19 |
Slack Block Kit 을 사용한 메시지 전송 (0) | 2022.03.09 |
yaml 파일을 사용해서 코드를 작성해보자 (0) | 2020.12.25 |
Python GUI 라이브러리 Tkinter 사용법 - Tutorial 2 (Label, LabelFrame, Button, Text, Entry) (0) | 2020.12.19 |
댓글