Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dscao authored Jun 28, 2022
1 parent 11c1f9a commit 5c0cd45
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion custom_components/wework_notify/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ def send_message(self, message="", **kwargs):
raise TypeError("视频地址未填写,消息类型为视频卡片时此项为必填!")
return
files = {"video": open(videopath, "rb")}
r = requests.post(curl, files=files)
try:
r = requests.post(curl, files=files, timeout=(20,180))
_LOGGER.debug("Uploading media " + videopath + " to WeChat servicers")
except requests.Timeout:
_LOGGER.error("File upload timeout, please try again later.")
return
re = json.loads(r.text)
if int(re['errcode']) != 0:
_LOGGER.error("Upload failed. Error Code " + str(re['errcode']) + ". " + str(re['errmsg']))
return
ree = re["media_id"]
media_id = str(ree)
msg = {"media_id": media_id, "title": title, "description": message}
Expand Down

0 comments on commit 5c0cd45

Please sign in to comment.