Commit 3a629f0
committed
gh-44672: Stop pre-resolving the FTP host in urllib.request
FTPHandler.ftp_open() resolved the host with socket.gethostbyname()
before connecting. gethostbyname() is IPv4-only, so an ftp:// URL for
an IPv6-only host failed there even when the server was reachable.
As diagnosed on the tracker in 2009, ftp_open() has no need to resolve
the host itself: it is passed to connect_ftp(), then to ftpwrapper, and
on to ftplib.FTP.connect(). That uses socket.create_connection(), which
resolves via getaddrinfo() and is IPv6-aware.
Remove the pre-resolution and let the host flow through unresolved. An
unresolvable host now raises socket.gaierror inside ftplib; gaierror is
an OSError and therefore in ftplib.all_errors, so ftp_open()'s existing
handler still turns it into URLError and callers see the same error type
as before.1 parent aeedae8 commit 3a629f0
3 files changed
Lines changed: 44 additions & 5 deletions
File tree
- Lib
- test
- urllib
- Misc/NEWS.d/next/Library
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
787 | 787 | | |
788 | 788 | | |
789 | 789 | | |
790 | | - | |
| 790 | + | |
791 | 791 | | |
792 | 792 | | |
793 | 793 | | |
| |||
797 | 797 | | |
798 | 798 | | |
799 | 799 | | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
800 | 839 | | |
801 | 840 | | |
802 | 841 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1526 | 1526 | | |
1527 | 1527 | | |
1528 | 1528 | | |
1529 | | - | |
1530 | | - | |
1531 | | - | |
1532 | | - | |
1533 | 1529 | | |
1534 | 1530 | | |
1535 | 1531 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments