Skip to content

fix: send languages() request as GET, not POST (#449) - #539

Open
Bryandero98 wants to merge 1 commit into
argosopentech:masterfrom
Bryandero98:fix/449-languages-get-request
Open

fix: send languages() request as GET, not POST (#449)#539
Bryandero98 wants to merge 1 commit into
argosopentech:masterfrom
Bryandero98:fix/449-languages-get-request

Conversation

@Bryandero98

Copy link
Copy Markdown

Bug

LibreTranslateAPI.languages() builds its request with request.Request(url, data=url_params.encode()). urllib.request.Request defaults to POST whenever data is set (regardless of intent), so this silently sends a POST to LibreTranslate's /languages endpoint, which only accepts GET — causing HTTPError: 405 METHOD NOT ALLOWED against current LibreTranslate servers.

translate() and detect() are correctly unaffected, since /translate and /detect do accept POST.

Fix

Adds method="GET" to the languages() request, exactly as suggested in #449 and confirmed against libretranslatepy's languages() (argos-translate's LibreTranslateAPI is based on it), which already carries this same fix.

Test plan

  • Added tests/test_apis.py: mocks urllib.request.urlopen to capture the built Request and assert its get_method(), covering languages() (now GET), translate() and detect() (still POST, to guard against a future regression there too) — no network access needed.
  • pytest tests/test_apis.py — 3/3 passing
  • black/isort — clean on the changed files

🤖 Generated with Claude Code

urllib.request.Request defaults to POST whenever a data body is set,
regardless of the HTTP method actually intended, unless method= is
passed explicitly. LibreTranslateAPI.languages() relied on that default,
so it silently sent a POST to an endpoint that only accepts GET, causing
HTTPError: 405 METHOD NOT ALLOWED against current LibreTranslate servers.

translate() and detect() are unaffected - LibreTranslate's /translate
and /detect endpoints do accept POST.

Mirrors the fix already applied to libretranslatepy's languages(),
which argos-translate's LibreTranslateAPI class is based on. Fixes argosopentech#449.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant