Skip to content

Commit

Permalink
Unescape text sent to Textlab API
Browse files Browse the repository at this point in the history
  • Loading branch information
timobrembeck committed Oct 26, 2022
1 parent 20f6659 commit 540e142
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions integreat_cms/textlab_api/textlab_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from urllib.error import HTTPError
from urllib.request import Request, urlopen

from html import unescape

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

Expand Down Expand Up @@ -48,7 +50,7 @@ def benchmark(self, text):
:raises urllib.error.HTTPError: if an http error occurred
"""
data = {"text": text, "locale_name": "de_DE"}
data = {"text": unescape(text), "locale_name": "de_DE"}
path = "/benchmark/5"
try:
response = self.post_request(path, data, self.token)
Expand Down Expand Up @@ -76,7 +78,9 @@ def post_request(path, data, auth_token=None):
:raises urllib.error.HTTPError: If the request failed
"""
data = json.dumps(data).encode("utf-8")
request = Request(f"{settings.TEXTLAB_API_URL}{path}", data=data, method="POST")
request = Request(
f"{settings.TEXTLAB_API_URL.rstrip('/')}{path}", data=data, method="POST"
)
if auth_token:
request.add_header("authorization", f"Bearer {auth_token}")
request.add_header("Content-Type", "application/json")
Expand Down

0 comments on commit 540e142

Please sign in to comment.