From 1e0b8d3af9911b69e0b62392e01837b92e4d8d3a Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Sat, 13 Feb 2021 20:27:41 +0100 Subject: [PATCH] workaround content-type issue --- Dockerfile | 12 ++++++++++++ hack/patches/mechsoup-browser-content-type.patch | 11 +++++++++++ pylokid/library/lodur.py | 4 ++-- pylokid/main.py | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 hack/patches/mechsoup-browser-content-type.patch diff --git a/Dockerfile b/Dockerfile index eda8ae7..8838d94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +## ----------- Step 1 FROM docker.io/python:3.9 AS base # Install pdftotext @@ -10,6 +11,7 @@ ENV HOME=/app WORKDIR ${HOME} +## ----------- Step 2 FROM base AS builder ENV PATH=${PATH}:${HOME}/.poetry/bin @@ -30,12 +32,22 @@ COPY . ./ RUN poetry build --format wheel +## ----------- Step 3 FROM builder AS installer COPY --from=builder \ /app/dist /app/dist RUN pip install /app/dist/pylokid-*-py3-none-any.whl +COPY hack/patches/*.patch /tmp + +# The ugliest possible way to workaround https://github.com/MechanicalSoup/MechanicalSoup/issues/356 +# For some unknown reasons Lodur now wants "Content-Type: application/pdf" set in the multipart +# data section. And as I couln't figure out yet how to do that in MechanicalSoup and I only upload PDFs +# I just patch it to hardcode it. YOLO +RUN patch -p0 /usr/local/lib/python3.9/site-packages/mechanicalsoup/browser.py < /tmp/mechsoup-browser-content-type.patch + +## ----------- Step 4 FROM base AS runtime COPY --from=installer \ diff --git a/hack/patches/mechsoup-browser-content-type.patch b/hack/patches/mechsoup-browser-content-type.patch new file mode 100644 index 0000000..761f485 --- /dev/null +++ b/hack/patches/mechsoup-browser-content-type.patch @@ -0,0 +1,11 @@ +--- /usr/local/lib/python3.9/site-packages/mechanicalsoup/browser.py.orig 2021-02-13 20:16:45.799025505 +0100 ++++ /usr/local/lib/python3.9/site-packages/mechanicalsoup/browser.py 2021-02-13 15:29:10.244575346 +0100 +@@ -201,7 +201,7 @@ + # If value is the empty string, we still pass it + # for consistency with browsers (see + # https://github.com/MechanicalSoup/MechanicalSoup/issues/250). +- files[name] = (filename, content) ++ files[name] = (filename, content, 'application/pdf') + else: + data.append((name, value)) + diff --git a/pylokid/library/lodur.py b/pylokid/library/lodur.py index b5ec502..1096d13 100644 --- a/pylokid/library/lodur.py +++ b/pylokid/library/lodur.py @@ -190,7 +190,7 @@ class Lodur: def einsatzrapport_alarmdepesche(self, f_id, file_path, webdav_client): """ Upload a file to Alarmdepesche """ - self.logger.info('[%s] Submitting File to Lodur "Alarmdepesche"', f_id) + self.logger.info('[%s] Submitting file %s to Lodur "Alarmdepesche"', f_id, file_path) # Login to lodur self.login() @@ -199,7 +199,7 @@ class Lodur: lodur_id = webdav_client.get_lodur_data(f_id)['event_id'] # Prepare the form - self.browser.open(self.url + '?modul=36&what=828&event=' + lodur_id) + self.browser.open('{}?modul=36&event={}&what=828'.format(self.url,lodur_id )) frm_alarmdepesche = self.browser.select_form('#frm_alarmdepesche') # Fill in form data diff --git a/pylokid/main.py b/pylokid/main.py index 4f62dd5..44eee87 100644 --- a/pylokid/main.py +++ b/pylokid/main.py @@ -34,7 +34,7 @@ LODUR_BASE_URL = os.getenv("LODUR_BASE_URL") HEARTBEAT_URL = os.getenv("HEARTBEAT_URL") PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN") PUSHOVER_USER_KEY = os.getenv("PUSHOVER_USER_KEY") -PYLOKID_VERSION = "2.1.2" +PYLOKID_VERSION = "2.2.0" def main(): """ main """