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

Brotli import error #4697 #5037

Closed
wants to merge 6 commits into from
Closed

Brotli import error #4697 #5037

wants to merge 6 commits into from

Conversation

Anupam-USP
Copy link

I tried to solve #4697 but if there is some problem please do let me know. Also this is my first pull request so if there is any formatting error, please correct me!

@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #5037 (21b00da) into master (ab037ab) will decrease coverage by 1.37%.
The diff coverage is 60.00%.

@@            Coverage Diff             @@
##           master    #5037      +/-   ##
==========================================
- Coverage   88.01%   86.63%   -1.38%     
==========================================
  Files         158      158              
  Lines        9736     9618     -118     
  Branches     1435     1436       +1     
==========================================
- Hits         8569     8333     -236     
- Misses        911     1027     +116     
- Partials      256      258       +2     
Impacted Files Coverage Δ
scrapy/downloadermiddlewares/httpcompression.py 84.48% <60.00%> (-2.79%) ⬇️
scrapy/robotstxt.py 52.00% <0.00%> (-45.54%) ⬇️
scrapy/shell.py 22.65% <0.00%> (-45.32%) ⬇️
scrapy/spiders/__init__.py 65.07% <0.00%> (-34.93%) ⬇️
scrapy/utils/ssl.py 65.85% <0.00%> (-4.88%) ⬇️
scrapy/extensions/memdebug.py 45.00% <0.00%> (-2.62%) ⬇️
scrapy/extensions/debug.py 44.73% <0.00%> (-1.42%) ⬇️
scrapy/extensions/throttle.py 44.89% <0.00%> (-1.11%) ⬇️
scrapy/core/downloader/handlers/http11.py 91.63% <0.00%> (-1.06%) ⬇️
scrapy/extensions/telnet.py 81.03% <0.00%> (-0.64%) ⬇️
... and 61 more

body = brotli.decompress(body)
try:
body = brotli.decompress(body)
except ImportError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception cannot happen here as far as I know, can it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here I have to make changes here and leave rest as it is, and if not installed than give a warning? Will it do the work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, please read the instructions in the issue:

If the user sets br manually on the Accept-Encoding header, I think we should:

  • Log a warning if brotlipy is not installed.
  • Have the middleware cause an error if the server sends the response br-encoded, and brotlipy is not installed.

So you need to raise an error here, it brotli is not installed, and in addition to this you need to log a warning if brotli is not installed but ACCEPTED_ENCODINGS contains 'br' (not sure which is the best place for this).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2021-03-12 201909

I think this much change can handle the issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are already catching ImportError in this file, you can just set a flag there and check it here.

Also, I'm not sure whether logging an error and returning the compressed body or raising an exception instead is a better way to handle this.

scrapy/downloadermiddlewares/httpcompression.py Outdated Show resolved Hide resolved
@Anupam-USP
Copy link
Author

Anupam-USP commented Mar 12, 2021

I am not able to push my change further, it is showing that This branch is 3 commits ahead, 6 commits behind scrapy:master. Should I close this pull request and create a new one or is there any other way? I have tried this solution.

Edit: I had made a new pr with my master branch but this branch's problem is still there. Should I close this PR now?

@wRAR
Copy link
Member

wRAR commented Mar 12, 2021

No, you shouldn't need to make new PRs if you just created additional commits in the same branch.

@Anupam-USP
Copy link
Author

Anupam-USP commented Mar 12, 2021

Actually I tried pushing with my master and it is recognized in #4697 conversation. In this branch I got the above error and not able to push.

Edit: Now my master is 1 branch ahead of scrapy/master. What should I do now? I think the best solution is to create a new pr with that and closing this one?

@Anupam-USP
Copy link
Author

I am really sorry, this was my first one so I got really confused. Should I close this one and create a fresh?

@Anupam-USP Anupam-USP closed this Mar 12, 2021
@Anupam-USP Anupam-USP mentioned this pull request Mar 12, 2021
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

2 participants