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

SOCKS proxy mechanism does not support IPv6 #15368

Open
romanrm opened this issue Jan 20, 2018 · 1 comment
Open

SOCKS proxy mechanism does not support IPv6 #15368

romanrm opened this issue Jan 20, 2018 · 1 comment
Labels
bug

Comments

@romanrm
Copy link

@romanrm romanrm commented Jan 20, 2018

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like this: [x])
  • Use the Preview tab to see what your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2018.01.18. If it's not, read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2018.01.18

Before submitting an issue make sure you have:

  • At least skimmed through the README, most notably the FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other

If the purpose of this issue is a bug report, site support request or you are not completely sure provide the full verbose output as follows:

$ youtube-dl.real -v --proxy socks5://fuyu.home.romanrm.net:1080/ https://www.youtube.com/watch?v=s8kOsoPZUkc
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'--proxy', u'socks5://fuyu.home.romanrm.net:1080/', u'https://www.youtube.com/watch?v=s8kOsoPZUkc']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2018.01.18
[debug] Python version 2.7.13 (CPython) - Linux-4.14.8-rm1+-x86_64-with-debian-8.10
[debug] exe versions: ffmpeg 3.2.5-1, ffprobe 3.2.5-1
[debug] Proxy map: {u'http': u'socks5://fuyu.home.romanrm.net:1080/', u'https': u'socks5://fuyu.home.romanrm.net:1080/'}
[youtube] s8kOsoPZUkc: Downloading webpage
ERROR: Unable to download webpage: <urlopen error [Errno -2] Name or service not known> (caused by URLError(gaierror(-2, 'Name or service not known'),))
  File "/usr/local/bin/youtube-dl.real/youtube_dl/extractor/common.py", line 517, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "/usr/local/bin/youtube-dl.real/youtube_dl/YoutubeDL.py", line 2198, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/usr/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/local/bin/youtube-dl.real/youtube_dl/utils.py", line 1089, in https_open
    req, **kwargs)
  File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)

$ host fuyu.home.romanrm.net
fuyu.home.romanrm.net has IPv6 address fd39::101

$ ping6 fuyu.home.romanrm.net
PING fuyu.home.romanrm.net(fd39::101 (fd39::101)) 56 data bytes
64 bytes from fd39::101 (fd39::101): icmp_seq=1 ttl=64 time=0.238 ms
64 bytes from fd39::101 (fd39::101): icmp_seq=2 ttl=64 time=0.232 ms
^C
--- fuyu.home.romanrm.net ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.232/0.235/0.238/0.003 ms

Description of your issue, suggested solution and other information

Does not work with proxy hostnames which resolve to IPv6 only.

Does not work with bare IPv6 specified (in brackets) instead of the hostname either. The error then becomes

ERROR: Unable to download webpage: <urlopen error [Errno -9] Address family for hostname not supported> (caused by URLError(gaierror(-9, 'Address family for hostname not supported'),))
@yan12125 yan12125 added the bug label Jan 20, 2018
@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jan 20, 2018

Temporary workaround:

diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 386897a85..8743c901b 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1048,7 +1048,7 @@ def make_socks_conn_class(base_class, socks_proxy):
 
     class SocksConnection(base_class):
         def connect(self):
-            self.sock = sockssocket()
+            self.sock = sockssocket(socket.AF_INET6)
             self.sock.setproxy(*proxy_args)
             if type(self.timeout) in (int, float):
                 self.sock.settimeout(self.timeout)

Note to myself: use socket.create_connection() instead of socket.socket.connect(). The former detects IPv4/IPv6 automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.