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
Enable downloading behind a proxy by using urllib2 #253
Enable downloading behind a proxy by using urllib2 #253
Conversation
Behind a proxy, `urllib` does not work with Python2 due to [Python issue 24599](https://bugs.python.org/issue24599). Instead of using `urllib`, let's implement `urlretrieve` with `urllib2`, which instead works and leave the Python3 implementation untouched (since that one works too). This fixes buildout issue #32. There's no need to change the `try: except:IOError` block where `urlretrieve` is used (line 195 in download.py) since the exceptions raised by `urllib2` are subclasses of `IOError` and will then be caught.
Please note that I have successfully run |
Is there any chance that this pull request is going to be considered? I appreciate any comments and am available to make the required changes if needed. |
Looks fine to me. |
Looks mostly OK to me. There is one thing that worries me a bit: the try/except results in different imported modules being available. It looks like either something is being imported (in python3 for instance) that isn't necessary. Or something is missing in python2. (Or I'm overlooking something). And the case difference between So: the patch does not look immediately obviously problem-free to me. It does look like it solves the issue. Could you look at the issues I've raised?
If you fix something and I don't respond within two days, feel free to remind me to take a look :-) |
@reinout thanks for your comment.
Since the Python issue 24599 only affects Python 2, I have tried to work around that only on the Python 2 side by redefining the I tried to be as conservative as possible in my changes, that's why I have essentially not modified the Python 3 code.
I agree that the class naming is a bit unclear, especially the It's definitely a good thing to remove the source of confusion, but I feel that it does not belong to this PR, probably it's best done in a separate commit. That said, I'll be happy to change the names in this PR if you think it's appropriate. Let me know what you think. |
|
See also the rejected pr #33 |
from urllib import request as urllib # for monkey patch below :( | ||
from urllib import request | ||
|
||
class PatchedURLopener(FancyURLopener): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed for clarity as requested by @reinout
@reinout, I have just pushed a commit to disambiguate the monkey-patched URL opener. On the other hand...
I use flake8 that in turn uses (also) pyflakes. I am not getting any warning about unused imports on both Python 2 and Python 3. To double check I have also run pyflakes directly on the As far as I can see, the imports seem to be in the right blocks.
These are the warnings that I get from flake8 on
Would you mind posting the errors you get from pyflakes? That would be really helpful. |
I didn't get any pyflakes errors as I only looked at your diff visually :-) I was only worrying about the different conditional imports being used later on by others that don't realize they're in a try/except. But on second thought we don't need to worry about that. The test runner will catch that. And there's no need to complicate the code further. Looks good, I'll merge it. |
…x_32 Enable downloading behind a proxy by using urllib2
I've added a changelog entry (directly in master). See 21344c7 Can you check if that's the right text? |
I've added a test fix on master (29a13cb, completely unrelated to your pull request) that hopefully gets the winbot tests running again. Those are scheduled in 1.5 hours. I'm waiting for the results from that and I think I'll just make a release. Nothing mayor has changed, but waiting for a bigger change isn't needed, right? |
Hm, the windows issue is almost fixed. I'll open a separate issue for that. I've changed the changelog a bit. Mentioning the python 2 issue is a good idea. I've released 2.4.1. Can you check to make sure it works for you? |
@reinout, thanks for that. I've just realized that we should've also said that this closes issue #32 (and that issue should be closed accordingly). Of course, it's not worth re-relasing just because of that. But it would be nice to have I will update those files in my next PR. If not, feel free to remind me before merging! Also, I will confirm the fix in the released version ASAP. |
I've closed #32 :-) I tend to forget those things sometimes. |
Behind a proxy,
urllib
does not work with Python2 due to Python issue24599.
Instead of using
urllib
, let's implementurlretrieve
withurllib2
, whichinstead works and leave the Python3 implementation untouched (since that
one works too).
This fixes buildout issue #32.
There's no need to change the
try: except:IOError
block whereurlretrieve
isused (line 195 in download.py) since the exceptions raised by
urllib2
are subclasses of
IOError
and will then be caught.