diff options
author | Elmer Miroslav Mosher Golovin <miroslav@mishamosher.com> | 2023-04-26 16:24:13 +0300 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2023-04-26 20:59:12 +0200 |
commit | d166a8b994dc393532fa7ea9bde87aacecd6ca57 (patch) | |
tree | 78ac936f6de6047a7099935d7880cef36d024678 /recording | |
parent | 585f1aba26b2c6a1a4fa1548cb3b0cb4e00b5d39 (diff) |
Use requests instead of urllib
Signed-off-by: Elmer Miroslav Mosher Golovin <miroslav@mishamosher.com>
Diffstat (limited to 'recording')
-rw-r--r-- | recording/pyproject.toml | 2 | ||||
-rw-r--r-- | recording/src/nextcloud/talk/recording/BackendNotifier.py | 23 |
2 files changed, 13 insertions, 12 deletions
diff --git a/recording/pyproject.toml b/recording/pyproject.toml index 35653c7e6..726022079 100644 --- a/recording/pyproject.toml +++ b/recording/pyproject.toml @@ -9,8 +9,8 @@ dependencies = [ "flask", "pulsectl", "pyvirtualdisplay>=2.0", + "requests-toolbelt", "selenium>=4.6.0", - "urllib3", "websocket-client", ] dynamic = ["version"] diff --git a/recording/src/nextcloud/talk/recording/BackendNotifier.py b/recording/src/nextcloud/talk/recording/BackendNotifier.py index 294e3fc63..0524889de 100644 --- a/recording/src/nextcloud/talk/recording/BackendNotifier.py +++ b/recording/src/nextcloud/talk/recording/BackendNotifier.py @@ -27,11 +27,12 @@ import hmac import json import logging import os +import requests import ssl from nextcloud.talk import recording +from requests import Request, Session +from requests_toolbelt import MultipartEncoder from secrets import token_urlsafe -from urllib.request import Request, urlopen -from urllib3 import encode_multipart_formdata from .Config import config @@ -62,13 +63,12 @@ def doRequest(backend, request, retries=3): """ context = None - if config.getBackendSkipVerify(backend): - context = ssl.create_default_context() - context.check_hostname = False - context.verify_mode = ssl.CERT_NONE + backendSkipVerify = config.getBackendSkipVerify(backend) try: - urlopen(request, context=context) + session = Session() + preparedRequest = session.prepare_request(request) + session.send(preparedRequest, verify=not backendSkipVerify) except Exception as exception: if retries > 1: logger.exception(f"Failed to send message to backend, {retries} retries left!") @@ -102,7 +102,7 @@ def backendRequest(backend, data): 'User-Agent': recording.USER_AGENT, } - backendRequest = Request(url, data, headers) + backendRequest = Request('POST', url, headers, data=data) doRequest(backend, backendRequest) @@ -200,18 +200,19 @@ def uploadRecording(backend, token, fileName, owner): 'owner': owner, 'file': (os.path.basename(fileName), fileContents), } - data, contentType = encode_multipart_formdata(data) + + multipartEncoder = MultipartEncoder(data) random, checksum = getRandomAndChecksum(backend, token.encode()) headers = { - 'Content-Type': contentType, + 'Content-Type': multipartEncoder.content_type, 'OCS-ApiRequest': 'true', 'Talk-Recording-Random': random, 'Talk-Recording-Checksum': checksum, 'User-Agent': recording.USER_AGENT, } - uploadRequest = Request(url, data, headers) + uploadRequest = Request('POST', url, headers, data=multipartEncoder) doRequest(backend, uploadRequest) |