title: youtube-dl returning <urlopen error [Errno 101] Network is unreachable>
body: <p>I have a google compute engine server that I'm trying to run youtube-dl. The server is in US Iowa, it is running debian 9.11</p>
  
  <p>This is the returned debug output:</p>
  
  <pre><code>youtube-dl -v https://youtu.be/tAfedFkfIiU
  
  [debug] System config: []
  [debug] User config: []
  [debug] Custom config: []
  [debug] Command-line args: [u'-v', u'https://youtu.be/tAfedFkfIiU']
  [debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
  [debug] youtube-dl version 2019.11.22
  [debug] Python version 2.7.13 (CPython) - Linux-4.9.0-11-amd64-x86_64-with-debian-9.11
  [debug] exe versions: none
  [debug] Proxy map: {}
  [youtube] tAfedFkfIiU: Downloading webpage
  [youtube] tAfedFkfIiU: Downloading video info webpage
  [debug] Default format spec: best/bestvideo+bestaudio
  [debug] Invoking downloader on u'https://r6---sn-5uaeznkz.googlevideo.com/videoplayback?expire=1574879492&amp;ei=pGzeXZCILYKGigTm34n4DQ&amp;ip=35.209.8.202&amp;id=o-AGcuKL5f7Y7Du-FaWbBZhMaLIsfRZox4FQAYtAj_ujri&amp;itag=22&amp;source=youtube&amp;requiressl=yes&amp;mm=31%2C26&amp;mn=sn-5uaeznkz%2Csn-tt1eln7e&amp;ms=au%2Conr&amp;mv=u&amp;mvi=5&amp;pl=16&amp;mime=video%2Fmp4&amp;ratebypass=yes&amp;dur=1008.047&amp;lmt=1574810711552172&amp;mt=1574857344&amp;fvip=6&amp;fexp=23842630&amp;beids=9466585&amp;c=WEB&amp;txp=5535432&amp;sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cratebypass%2Cdur%2Clmt&amp;sig=ALgxI2wwRAIgF6wvUZ9ogFyTSHe6BQib6D9Ib4x8Q4_FDuMP70zbnkgCID5CAhySBvgNYaeH9kwkP-vkecmrngFh7b8NYtnIs8RN&amp;lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl&amp;lsig=AHylml4wRQIhAMn1kcyvqttNBRifOFDTcOYcyGbSttZb4lyxiOq2j0JcAiAwnqjvkIAnBIDPOdjIxlDkZvVHhgqL_kLPj_NQEMyvoA%3D%3D'
  ERROR: unable to download video data: &lt;urlopen error [Errno 101] Network is unreachable&gt;
  Traceback (most recent call last):
    File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 1925, in process_info
      success = dl(filename, info_dict)
    File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 1864, in dl
      return fd.download(name, info)
    File "/usr/local/bin/youtube-dl/youtube_dl/downloader/common.py", line 366, in download
      return self.real_download(filename, info_dict)
    File "/usr/local/bin/youtube-dl/youtube_dl/downloader/http.py", line 341, in real_download
      establish_connection()
    File "/usr/local/bin/youtube-dl/youtube_dl/downloader/http.py", line 109, in establish_connection
      ctx.data = self.ydl.urlopen(request)
    File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 2237, 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/youtube_dl/utils.py", line 2724, in https_open
      req, **kwargs)
    File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
      raise URLError(err)
  URLError: &lt;urlopen error [Errno 101] Network is unreachable&gt;
  </code></pre>
  
  <p>Things I've tried:</p>
  
  <ul>
  <li>Allowed all network traffic through the google cloud firewall, both ingress and egress for all protocol types:
  <a href="https://i.stack.imgur.com/Zklac.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zklac.png" alt="firewall rules"></a></li>
  <li>Uninstalled curl and youtube-dl and reinstalled youtube-dl using wget</li>
  <li>Pinging youtube.com and google.com returns a good response.</li>
  <li>I can access my private web page from the server, so the ports are definitely working and theres definitely network access to everything outside the server.</li>
  <li>No network issues arose other than this.</li>
  <li>The direct link in the verbose output yields an "Access Denied" error, yet when trying youtube-dl locally, it returns a link that I can access and my friend with another IP can access, so it seems youtube-dl is returning non-accessible links? Unsure. <a href="https://i.stack.imgur.com/3ePOT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3ePOT.png" alt="access denied"></a></li>
  <li>I have not sent too many requests to get blacklisted, It didn't work from the start.</li>
  <li>The IP is ephemeral, it changes every time the server boots up (no static external IP set).</li>
  <li>Deleting and remaking the server instance from scratch does not fix the issue.</li>
  <li>The author of the library is adamant that it is a network issue on my side and not their side as seen in this github issue here: <a href="https://github.com/ytdl-org/youtube-dl/issues/23213" rel="nofollow noreferrer">https://github.com/ytdl-org/youtube-dl/issues/23213</a></li>
  <li>I thought it might be that <code>urllib2.urlopen</code> is unaccessible in gcloud, but I ran a small python script that runs the method and it pinged google.com properly.</li>
  <li>I cannot <code>wget</code> the direct link provided in the verbose log output. It times out. This is the output log of wget with -v and curl with -v:</li>
  </ul>
  
  <p>wget: </p>
  
  <pre><code>wget "https://r6---sn-5ualdn7y.googlevideo.com/videoplayback?expire=1575026099&amp;ei=U6ngXd3cDImjtQfFkKHACA&amp;ip=35.209.8.202&amp;id=o-ALJhUmz-vDQxpGilTFwb8v02UpFXo3JFaLZVvTV7BcGV&amp;itag=22&amp;source=youtube&amp;requiressl=yes&amp;mm=31%2C29&amp;mn=sn-5ualdn7y%2Csn-5uaeznrz&amp;ms=au%2Crdu&amp;mv=u&amp;mvi=5&amp;pl=16&amp;mime=video%2Fmp4&amp;ratebypass=yes&amp;dur=634.090&amp;lmt=1574939877997808&amp;mt=1575004312&amp;fvip=2&amp;fexp=23842630&amp;beids=9466587&amp;c=WEB&amp;txp=6531432&amp;sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cratebypass%2Cdur%2Clmt&amp;sig=ALgxI2wwRAIgWkUIL8i20_R0aDMs-UQmZq-EbHExzRFoP2ql6wqq3hoCIHKcxV7eU5sfcYxLzzVgJ1LgSoebvlUXnObwqDmzy7ym&amp;lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl&amp;lsig=AHylml4wRgIhANYw5qlL2ITIfsqPs5fveDiJljYvLCb8m4HLtoZDzTWmAiEA59uqA-cPmDAIgKRTYMXbxoegXat81xaZppigC76m7pQ%3D" -v
  The name is too long, 708 chars total.
  Trying to shorten...
  New name is videoplayback?expire=1575026099&amp;ei=U6ngXd3cDImjtQfFkKHACA&amp;ip=35.209.8.202&amp;id=o-ALJhUmz-vDQxpGilTFwb8v02UpFXo3JFaLZVvTV7BcGV&amp;itag=22&amp;source=youtube&amp;requiressl=yes&amp;mm=31%2C29&amp;mn=sn-5ualdn7y%2Csn-5uaeznrz&amp;ms=au%2Crdu&amp;mv=u&amp;mvi=5&amp;pl=16&amp;mime=.
  --2019-11-29 05:15:14--  https://r6---sn-5ualdn7y.googlevideo.com/videoplayback?expire=1575026099&amp;ei=U6ngXd3cDImjtQfFkKHACA&amp;ip=35.209.8.202&amp;id=o-ALJhUmz-vDQxpGilTFwb8v02UpFXo3JFaLZVvTV7BcGV&amp;itag=22&amp;source=youtube&amp;requiressl=yes&amp;mm=31%2C29&amp;mn=sn-5ualdn7y%2Csn-5uaeznrz&amp;ms=au%2Crdu&amp;mv=u&amp;mvi=5&amp;pl=16&amp;mime=video%2Fmp4&amp;ratebypass=yes&amp;dur=634.090&amp;lmt=1574939877997808&amp;mt=1575004312&amp;fvip=2&amp;fexp=23842630&amp;beids=9466587&amp;c=WEB&amp;txp=6531432&amp;sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cratebypass%2Cdur%2Clmt&amp;sig=ALgxI2wwRAIgWkUIL8i20_R0aDMs-UQmZq-EbHExzRFoP2ql6wqq3hoCIHKcxV7eU5sfcYxLzzVgJ1LgSoebvlUXnObwqDmzy7ym&amp;lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl&amp;lsig=AHylml4wRgIhANYw5qlL2ITIfsqPs5fveDiJljYvLCb8m4HLtoZDzTWmAiEA59uqA-cPmDAIgKRTYMXbxoegXat81xaZppigC76m7pQ%3D
  Resolving r6---sn-5ualdn7y.googlevideo.com (r6---sn-5ualdn7y.googlevideo.com)... 173.194.147.204, 2607:f8b0:4002:35::c
  Connecting to r6---sn-5ualdn7y.googlevideo.com (r6---sn-5ualdn7y.googlevideo.com)|173.194.147.204|:443... failed: Connection timed out.
  Connecting to r6---sn-5ualdn7y.googlevideo.com (r6---sn-5ualdn7y.googlevideo.com)|2607:f8b0:4002:35::c|:443... failed: Network is unreachable.
  </code></pre>
  
  <p>curl: </p>
  
  <pre><code>curl -O -v https://r2---sn-hgn7rn7r.googlevideo.com/videoplayback?expire=1575026099&amp;ei=U6ngXd3cDImjtQfFkKHACA&amp;ip=35.209.8.202&amp;id=o-ALJhUmz-vDQxpGilTFwb8v02UpFXo3JFaLZVvTV7BcGV&amp;itag=22&amp;source=youtube&amp;requiressl=yes&amp;mime=video/mp4&amp;ratebypass=yes&amp;dur=634.090&amp;lmt=1574939877997808&amp;fvip=2&amp;fexp=9466587,23842630&amp;beids=9466587&amp;c=WEB&amp;txp=6531432&amp;sparams=expire,ei,ip,id,itag,source,requiressl,mime,ratebypass,dur,lmt&amp;sig=ALgxI2wwRAIgWkUIL8i20_R0aDMs-UQmZq-EbHExzRFoP2ql6wqq3hoCIHKcxV7eU5sfcYxLzzVgJ1LgSoebvlUXnObwqDmzy7ym&amp;rm=sn-5uakd7d&amp;req_id=db99eec2ba1fa3ee&amp;ipbypass=yes&amp;redirect_counter=2&amp;cm2rm=sn-uxgg5oxu-cxte7l&amp;cms_redirect=yes&amp;mip=213.204.90.117&amp;mm=29&amp;mn=sn-hgn7rn7r&amp;ms=rdu&amp;mt=1575004548&amp;mv=m&amp;mvi=1&amp;pl=24&amp;lsparams=ipbypass,mip,mm,mn,ms,mv,mvi,pl&amp;lsig=AHylml4wRQIgK50gSfkEix6Q7q9n2GTk7GQOn6YEZ1NqiX4l8UwDHhQCIQDT4Q4KoFB6Dck1vQj0FO27LvNA8PMVyNJOaFMcU9yutg==
  [1] 3670
  [2] 3671
  [3] 3672
  [4] 3673
  [5] 3674
  [6] 3675
  [7] 3676
  [8] 3677
  [9] 3678
  [10] 3679
  [11] 3680
  [12] 3681
  [13] 3682
  [14] 3683
  [15] 3684
  [16] 3685
  [17] 3686
  [18] 3687
  [19] 3688
  [20] 3689
  [21] 3690
  [22] 3691
  [23] 3692
  [24] 3693
  [25] 3694
  [26] 3695
  [27] 3696
  [28] 3697
  [29] 3698
  [30] 3699
  [31] 3700
  [32] 3701
  [33] 3702
  [2]   Done                    ei=U6ngXd3cDImjtQfFkKHACA
  [3]   Done                    ip=35.209.8.202
  [4]   Done                    id=o-ALJhUmz-vDQxpGilTFwb8v02UpFXo3JFaLZVvTV7BcGV
  [5]   Done                    itag=22
  [6]   Done                    source=youtube
  [7]   Done                    requiressl=yes
  [8]   Done                    mime=video/mp4
  [9]   Done                    ratebypass=yes
  [10]   Done                    dur=634.090
  [11]   Done                    lmt=1574939877997808
  [12]   Done                    fvip=2
  [13]   Done                    fexp=9466587,23842630
  [14]   Done                    beids=9466587
  [15]   Done                    c=WEB
  [16]   Done                    txp=6531432
  [17]   Done                    sparams=expire,ei,ip,id,itag,source,requiressl,mime,ratebypass,dur,lmt
  [18]   Done                    sig=ALgxI2wwRAIgWkUIL8i20_R0aDMs-UQmZq-EbHExzRFoP2ql6wqq3hoCIHKcxV7eU5sfcYxLzzVgJ1LgSoebvlUXnObwqDmzy7ym
  [19]   Done                    rm=sn-5uakd7d
  [20]   Done                    req_id=db99eec2ba1fa3ee
  [21]   Done                    ipbypass=yes
  [22]   Done                    redirect_counter=2
     % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 172.217.130.231...
  * TCP_NODELAY set
  *   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
  *   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
    0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0*   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
    0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0*   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
    0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0*   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
    0     0    0     0    0     0      0      0 --:--:--  0:00:04 --:--:--     0*   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
    0     0    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0*   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
    0     0    0     0    0     0      0      0 --:--:--  0:00:06 --:--:--     0*   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
    0     0    0     0    0     0      0      0 --:--:--  0:00:07 --:--:--     0*   Trying 2a00:1450:4006:9::7...
  (continues)
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
    0     0    0     0    0     0      0      0 --:--:--  0:02:09 --:--:--     0* connect to 172.217.130.231 port 443 failed: Connection timed out
  *   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
  *   Trying 2a00:1450:4006:9::7...
  * TCP_NODELAY set
  * Immediate connect fail for 2a00:1450:4006:9::7: Network is unreachable
  * Failed to connect to r2---sn-hgn7rn7r.googlevideo.com port 443: Connection timed out
  * Closing connection 0
  curl: (7) Failed to connect to r2---sn-hgn7rn7r.googlevideo.com port 443: Connection timed out
  </code></pre>
  
  <ul>
  <li>I have tried several youtube urls. Several different videos, with different formats of the URL.</li>
  <li>It is not a geo-blocking issue, the server is hosted in US Iowa.</li>
  <li>I've tried updating python to latest (3.5/6), same result.</li>
  </ul>
  
  <p>I honestly ran out of ideas to debug this further.</p>
  
  <p>EDIT: Something has sporadically changed, I can now access the direct link from the verbose output log in my local browser which I COULDN'T do before. I did not change anything since this question. Is my server's IP address being blocked? I never sent several requests to youtube to get black-listed so fast. Maybe it's not being blacklisted though, I still can't tell if it's a firewall issue. If it were a black-list issue, the verbose outputs of curl and wget would've returned an Access Denied error. So what's going on here?</p>