From 3149478363c443dfef4b1e63a77d1dcae15114a6 Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Tue, 25 May 2021 21:50:44 +0200 Subject: [PATCH] Replaced urllib.request by requests --- matrix.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/matrix.py b/matrix.py index c91a784..d667b89 100644 --- a/matrix.py +++ b/matrix.py @@ -28,7 +28,7 @@ import os import random import string import sys -import urllib.request +import requests MATRIXHOST = os.environ["NOTIFY_PARAMETER_1"] MATRIXTOKEN = os.environ["NOTIFY_PARAMETER_2"] @@ -86,12 +86,9 @@ matrixData = matrixData.encode("utf-8") # Random transaction ID for Matrix Homeserver. txnId = ''.join(random.SystemRandom().choice( string.ascii_uppercase + string.digits) for _ in range(16)) - # Authorization headers and etc. matrixHeaders = {"Authorization": "Bearer " + MATRIXTOKEN, - "Content-Type": "application/json", "Content-Length": len(matrixData)} + "Content-Type": "application/json", "Content-Length": str(len(matrixData))} # Request. -req = urllib.request.Request(url=MATRIXHOST + "/_matrix/client/r0/rooms/" + MATRIXROOM + - "/send/m.room.message/" + txnId, data=matrixData, headers=matrixHeaders, method="PUT") -# Exec. -urllib.request.urlopen(req) +req = requests.put(url=MATRIXHOST + "/_matrix/client/r0/rooms/" + MATRIXROOM + + "/send/m.room.message/" + txnId, data=matrixData, headers=matrixHeaders)