Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up[2.7] bpo-27973 - Fix for urllib.urlretrieve() failing on second ftp transfer #1040
Conversation
@@ -42,6 +42,8 @@ Extension Modules | |||
Library | |||
------- | |||
|
|||
- bpo-27973 - Fix for urllib.urlretrieve() failing on second ftp transfer. |
This comment has been minimized.
This comment has been minimized.
try: | ||
for _ in range(3): | ||
fp = urllib.urlopen(self.FTP_TEST_FILE) | ||
# closing fp is not required. |
This comment has been minimized.
This comment has been minimized.
serhiy-storchaka
Apr 10, 2017
Member
This test can behave differently in CPython and PyPy. If fp can remain unclosed, maybe save it in a list, so that it will not be closed in all implementations? If the file is not closed explicitly it is worth to call test_support.gc_collect() after removing all references to it. This will make the behavior more predicable in all implementations.
for _ in range(3): | ||
urllib.FancyURLopener().retrieve( | ||
self.FTP_TEST_FILE, | ||
tempfile.NamedTemporaryFile().name) |
This comment has been minimized.
This comment has been minimized.
serhiy-storchaka
Apr 10, 2017
Member
The NamedTemporaryFile object can be collected right after getting its name. Save a reference to tempfile.NamedTemporaryFile() until retrieve a file or better use a context manager.
This comment has been minimized.
This comment has been minimized.
doctoryes
commented
Sep 13, 2017
Has this fix stalled? I'm able to reproduce this problem in Python 2.7.13 with the following steps:
These steps result in this error:
|
@@ -213,14 +214,44 @@ def test_context_argument(self): | |||
self.assertIn("Python", response.read()) | |||
|
|||
|
|||
class urlopen_FTPTest(unittest.TestCase): | |||
# TODO: https://github.com/python/pythondotorg/issues/1069 |
This comment has been minimized.
This comment has been minimized.
|
||
with test_support.transient_internet(self.FTP_TEST_FILE): | ||
try: | ||
for _ in range(3): |
This comment has been minimized.
This comment has been minimized.
ZackerySpytz
Sep 8, 2019
Contributor
for _ in range(3):
is used a couple of times in this class. I think the 3 should be replaced with a constant.
fp = urllib.urlopen(self.FTP_TEST_FILE) | ||
# closing fp is not required. | ||
except IOError as e: | ||
self.fail("Failed FTP binary file open." |
This comment has been minimized.
This comment has been minimized.
ZackerySpytz
Sep 8, 2019
Contributor
There should be a space after this period (or a space just before the "Error" on the next line).
If you still want to pursue this, it will need to be rebased and blurbed. |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Sep 12, 2019
When you're done making the requested changes, leave the comment: |
This comment has been minimized.
This comment has been minimized.
I have made the requested changes; please review again. @benjaminp - Please take a call to include the final 2.7 release. Thanks. |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Dec 30, 2019
Thanks for making the requested changes! @benjaminp: please review the changes made to this pull request. |
Since this is essentially a revert, it seems good. |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Dec 31, 2019
@orsenthil: Please replace |
This comment has been minimized.
This comment has been minimized.
This PR is failing in several 2.7 buildbots:
Example failure: |
orsenthil commentedApr 8, 2017
•
edited by bedevere-bot
The problem and the solution has been described well in the msg: http://bugs.python.org/issue27973#msg286016
This just brings the patch to github.
https://bugs.python.org/issue27973