curl_cffi: [BUG] URLs being url decoded before request is sent
Describe the bug
We have an endpoint which utilizes IDs that contain URL-encoded special characters. After the update to curl_cffi 0.7.2, these requests began failing. After some investigation we found the package had started url-decoding the url before sending the request. In our case, the special characters are %2f or /, which causes the URL to be malformed and the request to fail.
To Reproduce
from curl_cffi import requests
# used my own website because I know it doesn't redirect on 404
url = 'https://duncanlutz.dev/example/%2f%2f%2f'
session = requests.Session()
response = session.get(url)
# Asserts currently fail
assert response.url == url
I’ve also put a repo up with the example: https://github.com/duncanlutz/curl_cffi_issue
Expected behavior In previous versions, the url had not been decoded before making the request. Our expected behavior would be to either not decode the URL, or provide a way to opt out of decoding.
Versions
- OS: macOS Sonoma 14.1.1
- curl_cffi version 0.7.2
pip freezedump:
certifi==2024.8.30
cffi==1.17.1
curl_cffi==0.7.2
pycparser==2.22
typing_extensions==4.12.2
Additional context
- Which session are you using? async or sync? We are using sync.
- If using async session, which loop implementation are you using?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 15 (8 by maintainers)
Commits related to this issue
- [networking] Pin `curl-cffi` version to < 0.7.2 Ref: https://github.com/lexiforest/curl_cffi/issues/394 Authored by: bashonly — committed to bashonly/yt-dlp by bashonly 2 years ago
- [networking] Pin `curl-cffi` version to < 0.7.2 (#11092) Ref: https://github.com/lexiforest/curl_cffi/issues/394 Authored by: bashonly — committed to yt-dlp/yt-dlp by bashonly 2 years ago
- Add `quote` parameter to specify which character should be percent-encoded in path and query, close #394 — committed to lexiforest/curl_cffi by lexiforest 2 years ago
- require curl_cffi >= 0.7.3 https://github.com/lexiforest/curl_cffi/issues/394 there was a problem in 0.7.2 causing quoted url to be unquoted unexpectedly. — committed to 5j9/citer by 5j9 2 years ago
- bugfix: do not unquote url when params are provided, close #394 — committed to lexiforest/curl_cffi by lexiforest 2 years ago
- bugfix: do not unquote url when params are provided, close #394 (#507) — committed to CaoYunzhou/curl_cffi by lexiforest 2 years ago
- [networking] Pin `curl-cffi` version to < 0.7.2 (#11092) Ref: https://github.com/lexiforest/curl_cffi/issues/394 Authored by: bashonly — committed to subrat-lima/yt-dlp by bashonly 2 years ago
@lexiforest.
Since curl_cffi aims to be API-compatible with the requests library, may I suggest using requests’ requote_uri()? It is the standard way the library deals with URL-encoded strings.
It covers #333 while also fixing this current issue.
+1, our test suite has also picked this up.
Might be due to https://github.com/lexiforest/curl_cffi/commit/9c13b830f378687900ddbb953ae8edb9998b3b1d
As a side note, I don’t think you should be url-decoding and then re-encoding the query component, as it may not produce the same result. https://datatracker.ietf.org/doc/html/rfc3986#section-2.4
Here’s what urllib3 does, for example.: https://github.com/urllib3/urllib3/blob/main/src/urllib3/util/url.py#L227