python / cpython

The Python programming language
https://www.python.org
Other
63.14k stars 30.23k forks source link

`test.test_urllib2.HandlerTests.test_ftp_error` fails without network access (running `-u-network`) #125584

Closed mgorny closed 6 days ago

mgorny commented 6 days ago

Bug report

Bug description:

The newly added test_ftp_error (in 77133f570dcad599e5b1199c39e999bfac959ae2, FWICS) is failing in environments without Internet access, even though it is not marked as needing the "network" resource:

======================================================================
FAIL: test_ftp_error (test.test_urllib2.HandlerTests.test_ftp_error)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-lang/python-3.14.0_alpha1/work/Python-3.14.0a1/Lib/urllib/request.py", line 1531, in ftp_open
    host = socket.gethostbyname(host)
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/tmp/portage/dev-lang/python-3.14.0_alpha1/work/Python-3.14.0a1/Lib/test/test_urllib2.py", line 811, in test_ftp_error
    urlopen("ftp://www.pythontest.net/")
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/portage/dev-lang/python-3.14.0_alpha1/work/Python-3.14.0a1/Lib/urllib/request.py", line 489, in open
    response = self._open(req, data)
  File "/var/tmp/portage/dev-lang/python-3.14.0_alpha1/work/Python-3.14.0a1/Lib/urllib/request.py", line 506, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
                              '_open', req)
  File "/var/tmp/portage/dev-lang/python-3.14.0_alpha1/work/Python-3.14.0a1/Lib/urllib/request.py", line 466, in _call_chain
    result = func(*args)
  File "/var/tmp/portage/dev-lang/python-3.14.0_alpha1/work/Python-3.14.0a1/Lib/urllib/request.py", line 1533, in ftp_open
    raise URLError(msg)
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/tmp/portage/dev-lang/python-3.14.0_alpha1/work/Python-3.14.0a1/Lib/test/test_urllib2.py", line 813, in test_ftp_error
    self.assertEqual(raised.reason,
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
                     f"ftp error: {exception.args[0]}")
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: gaierror(-3, 'Temporary failure in name resolution') != 'ftp error: 500 OOPS: cannot change directory:/nonexistent'

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Eclips4 commented 6 days ago

Hello! Thanks for the report. Would you like to send a PR with fix?

mgorny commented 6 days ago

Sure, I can try making one in a minute.

mgorny commented 6 days ago

Filed #125586 for it.