Skip to content
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

Fix AttributeError when the brotli module is installed #1572

Merged
merged 1 commit into from Apr 22, 2019

Conversation

elprans
Copy link
Contributor

@elprans elprans commented Apr 22, 2019

The recent addition of Brotli support is broken, since it uses an
incorrect spelling of brotli.error, resulting in:

Python 2.7.16 (default, Mar  8 2019, 14:51:39)
[GCC 8.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib3.response
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "site-packages/urllib3/__init__.py", line 7, in <module>
    from .connectionpool import (
  File "site-packages/urllib3/connectionpool.py", line 37, in <module>
    from .response import HTTPResponse
  File "site-packages/urllib3/response.py", line 144, in <module>
    class HTTPResponse(io.IOBase):
  File "site-packages/urllib3/response.py", line 344, in HTTPResponse
    DECODER_ERROR_CLASSES += (brotli.Error,)
AttributeError: 'module' object has no attribute 'Error'

The recent addition of Brotli support is broken, since it uses an
incorrect spelling of `brotli.error`, resulting in:

    Python 2.7.16 (default, Mar  8 2019, 14:51:39)
    [GCC 8.2.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import urllib3.response
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "site-packages/urllib3/__init__.py", line 7, in <module>
        from .connectionpool import (
      File "site-packages/urllib3/connectionpool.py", line 37, in <module>
        from .response import HTTPResponse
      File "site-packages/urllib3/response.py", line 144, in <module>
        class HTTPResponse(io.IOBase):
      File "site-packages/urllib3/response.py", line 344, in HTTPResponse
        DECODER_ERROR_CLASSES += (brotli.Error,)
    AttributeError: 'module' object has no attribute 'Error'
@codecov-io
Copy link

codecov-io commented Apr 22, 2019

Codecov Report

Merging #1572 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1572   +/-   ##
=======================================
  Coverage   99.89%   99.89%           
=======================================
  Files          22       22           
  Lines        1873     1873           
=======================================
  Hits         1871     1871           
  Misses          2        2
Impacted Files Coverage Δ
src/urllib3/response.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c3157af...c2787a5. Read the comment docs.

@sethmlarson
Copy link
Member

What version of brotlipy are you using? brotli.Error has been available since 0.5.1.

@elprans
Copy link
Contributor Author

elprans commented Apr 22, 2019

Hm. We are actually using the google's package (which has the same module name):

https://github.com/google/brotli/blob/4b2b2d4f83ffeaac7708e44409fe34896a01a278/python/brotli.py#L55-L56

@sethmlarson
Copy link
Member

That makes sense, we'll have to try testing against that package as well...

@elprans
Copy link
Contributor Author

elprans commented Apr 22, 2019

brotlipy actually defines the lowercase error as an alias to Error for compatibility with the original brotli module:

https://github.com/python-hyper/brotlipy/blob/ffddf2ea5adc584c8c353d246bb1077b7e781b63/src/brotli/brotli.py#L18-L22

@sethmlarson
Copy link
Member

Yeah this fix would definitely work, I'm going to merge this and then start preparing some integration tests so that this isn't an issue in the future and also prepare for a 1.25.1 release.

Thanks for this!

@mnagel
Copy link

mnagel commented Sep 9, 2019

we require this fix in our product, unfortunately there is no released version of urllib3 containing this fix. what's the schedule for a release including this?

@sethmlarson
Copy link
Member

Dobatymo pushed a commit to Dobatymo/urllib3 that referenced this pull request Mar 16, 2022
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.

None yet

4 participants