fix: send languages() request as GET, not POST (#449) - #539
Open
Bryandero98 wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
LibreTranslateAPI.languages()builds its request withrequest.Request(url, data=url_params.encode()).urllib.request.Requestdefaults to POST wheneverdatais set (regardless of intent), so this silently sends a POST to LibreTranslate's/languagesendpoint, which only accepts GET — causingHTTPError: 405 METHOD NOT ALLOWEDagainst current LibreTranslate servers.translate()anddetect()are correctly unaffected, since/translateand/detectdo accept POST.Fix
Adds
method="GET"to thelanguages()request, exactly as suggested in #449 and confirmed againstlibretranslatepy'slanguages()(argos-translate'sLibreTranslateAPIis based on it), which already carries this same fix.Test plan
tests/test_apis.py: mocksurllib.request.urlopento capture the builtRequestand assert itsget_method(), coveringlanguages()(now GET),translate()anddetect()(still POST, to guard against a future regression there too) — no network access needed.pytest tests/test_apis.py— 3/3 passingblack/isort— clean on the changed files🤖 Generated with Claude Code