-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Brotli algorithm encoding #4525
Comments
This is dependent upon urllib3/urllib3#713 which has stalled. Until then, we cannot add it ourselves and the work must be tracked in urllib3. |
similiar problem
|
@sigmavirus24 now that brotli has landed in urllib3 (urllib3/urllib3#1532, urllib3/urllib3#1533, urllib3/urllib3#1534), should we reopen this issue or do you want me to open a new one? |
While not ideal, the best work around I came up for the time being... if anyone actually needs it.. I am actually doing this in a super() for one of my modules.. import brotli
session = requests.session()
rsp = session.get('http://somehostwithbrotli/')
if resp.headers.get('Content-Encoding') == 'br':
resp._content = brotli.decompress(resp.content)
# As content is a function, which calls upon the attribute variable _content.
print resp.content
# etc... etc...
print resp.text |
Since Brotli is not installed via urllib3 by default, you have to install
or
After that, just specify >>> import requests
>>> requests.__version__
'2.22.0'
>>> headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0', 'Accept-Encoding': 'br, gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}
>>> r = requests.get('https://www.google.com/', headers=headers)
>>> r.headers['Content-Encoding']
'br'
>>> r.text[:10]
'<!doctype ' |
Not sure why they're using brotlipy when the pypi brotli package is maintained by google and brotli was initially written by... google |
yea you might be right i just saw that myself , that said... 2.7+ would mean py3 ... and frankly wtf uses below 2.7? |
@VeNoMouS You are right. I also read the
|
ah, nice spotting there :) |
Can we please reopen this, @nateprewitt or @sethmlarson ? - Brotli support is in urllib since 1.25.1 released in 2019-04-24. Would you accept a PR for this feature? |
@gdubicki I'd accept a PR adding Brotli support if it's detected. |
by the urllib3 version
by the urllib3 version
by the urllib3 version
by the urllib3 version (>= 1.23.1) and brotli package being present
by the urllib3 version (>= 1.23.1) and brotli package being present
by the urllib3 version (>= 1.23.1) and brotli package being present
Can you please check out my draft (but almost complete, I think) PR #5554, @sethmlarson ? |
by the urllib3 version (>= 1.25.1) and brotli package being present
…ts, be sure that users cant accidently use this content type encoding in the headers
I think fixing this is a matter of utilizing urllib3.util.make_headers(keep_alive=True, accept_encoding=True, user_agent='...') in requests.requests.default_headers() . This will automatically add Urllib3 can decode brotli, if https://pypi.org/project/Brotli/ or https://pypi.org/project/brotlicffi/ are installed. When they are installed, I propose changing the patch to use |
While everybody talks about Brotli-Encoding support, I guess it is meant brotli decoding. When the http agent sends “Accept-Encoding: br’, the server encodes with brotli, and the http agents decodes. Is this about decoding brotli compressed content in the http agent (requester), or is this case about adding brotli-encoding for servers? |
#5783 proposes a patch to request and decode in brotli, transparently by Requests, whenever the package |
This was resolved in #5783. |
Right now, only gzip and deflate are supported. Brotli is pretty common, it ought to be too.
Expected Result
Responses encoded with the Brotli Algorithm should be decoded
Actual Result
Brotli responses need to be manually decoded
Reproduction Steps
{
"chardet": {
"version": "3.0.4"
},
"cryptography": {
"version": "2.0.3"
},
"idna": {
"version": "2.6"
},
"implementation": {
"name": "CPython",
"version": "3.4.3"
},
"platform": {
"release": "3.13.0-142-generic",
"system": "Linux"
},
"pyOpenSSL": {
"openssl_version": "1010006f",
"version": "17.2.0"
},
"requests": {
"version": "2.18.4"
},
"system_ssl": {
"version": "1000106f"
},
"urllib3": {
"version": "1.22"
},
"using_pyopenssl": true
}
The text was updated successfully, but these errors were encountered: