Repository: youtube-dl
Issue: Youtube download error - <urlopen error [Errno 22] Invalid argument>
Labels: cant-reproduce

## 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 *2017.12.02*. If it's not, read [this FAQ entry](https://github.com/rg3/youtube-dl/blob/master/README.md#how-do-i-update-youtube-dl) and update. Issues with outdated version will be rejected.
- [x] I've **verified** and **I assure** that I'm running youtube-dl **2017.12.02**

### Before submitting an *issue* make sure you have:
- [x] At least skimmed through the [README](https://github.com/rg3/youtube-dl/blob/master/README.md), **most notably** the [FAQ](https://github.com/rg3/youtube-dl#faq) and [BUGS](https://github.com/rg3/youtube-dl#bugs) sections
- [x] [Searched](https://github.com/rg3/youtube-dl/search?type=Issues) the bugtracker for similar issues including closed ones

### What is the purpose of your *issue*?
- [x] 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

---

```
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'https://www.youtube.com/watch?v=ejPe2eYhjR4', u'-v']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2017.12.02
[debug] Python version 2.7.14 - Darwin-17.2.0-x86_64-i386-64bit
[debug] exe versions: ffmpeg 3.4, ffprobe 3.4
[debug] Proxy map: {}
[youtube] ejPe2eYhjR4: Downloading webpage
[youtube] ejPe2eYhjR4: Downloading video info webpage
[youtube] ejPe2eYhjR4: Extracting video information
[youtube] ejPe2eYhjR4: Downloading MPD manifest
[debug] Default format spec: bestvideo+bestaudio/best
[debug] Invoking downloader on u'https://r1---sn-nu5gi0c-npok.googlevideo.com/videoplayback?id=7a33ded9e6218d1e&itag=137&source=youtube&requiressl=yes&ei=V0knWt3fBIbsowOg1IfgCg&mn=sn-nu5gi0c-npok&mm=31&ms=au&mv=u&pl=43&ratebypass=yes&mime=video/mp4&gir=yes&clen=92139427&lmt=1512416704858018&dur=195.153&signature=32
9F0B18B27DB4AA9F6F9C8BF58835F8984356C8.FBE391BCB4F0C2A7BEDF79D7635AAD71E92886&mt=1512523703&key=dg_yt0&ip=2406:3000:11:1022:9d80:1845:6e37:751d&ipbits=0&expire=1512545719&sparams=ip,ipbits,expire,id,itag,source,requiressl,ei,mn,mm,ms,mv,pl,ratebypass,mime,gir,clen,lmt,dur'
ERROR: unable to download video data: <urlopen error [Errno 22] Invalid argument>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/youtube_dl/YoutubeDL.py", line 1887, in process_info
    partial_success = dl(fname, new_info)
  File "/usr/local/lib/python2.7/site-packages/youtube_dl/YoutubeDL.py", line 1832, in dl
    return fd.download(name, info)
  File "/usr/local/lib/python2.7/site-packages/youtube_dl/downloader/common.py", line 361, in download
    return self.real_download(filename, info_dict)
  File "/usr/local/lib/python2.7/site-packages/youtube_dl/downloader/http.py", line 286, in real_download
    establish_connection()
  File "/usr/local/lib/python2.7/site-packages/youtube_dl/downloader/http.py", line 74, in establish_connection
    ctx.data = self.ydl.urlopen(request)
  File "/usr/local/lib/python2.7/site-packages/youtube_dl/YoutubeDL.py", line 2196, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/site-packages/youtube_dl/utils.py", line 1086, in https_open
    req, **kwargs)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 22] Invalid argument>
```
For completeness, I tested the URL with `curl`

```
$ curl -svo v "https://r1---sn-nu5gi0c-npok.googlevideo.com/videoplayback?id=7a33ded9e6218d1e&itag=137&source=youtube&requiressl=yes&ei=V0knWt3fBIbsowOg1IfgCg&mn=sn-nu5gi0c-npok&mm=31&ms=au&mv=u&pl=43&ratebypass=yes&mime=video/mp4&gir=yes&clen=92139427&lmt=1512416704858018&dur=195.153&signature=329F0B18B27DB4AA9F6F9C8BF58835F8984356C8.FBE391BCB4F0C2A7BEDF79D7635AAD71E92886&mt=1512523703&key=dg_yt0&ip=2406:3000:11:1022:9d80:1845:6e37:751d&ipbits=0&expire=1512545719&sparams=ip,ipbits,expire,id,itag,source,requiressl,ei,mn,mm,ms,mv,pl,ratebypass,mime,gir,clen,lmt,dur"
*   Trying 2406:3001:22:1::c...
* TCP_NODELAY set
*   Trying 203.116.189.12...
* TCP_NODELAY set
* Connected to r1---sn-nu5gi0c-npok.googlevideo.com (203.116.189.12) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /usr/local/etc/openssl/cert.pem
  CApath: /usr/local/etc/openssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
} [5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [87 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [3297 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.googlevideo.com
*  start date: Nov 16 20:14:00 2017 GMT
*  expire date: Feb  8 20:14:00 2018 GMT
*  subjectAltName: host "r1---sn-nu5gi0c-npok.googlevideo.com" matched cert's "*.googlevideo.com"
*  issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*  SSL certificate verify ok.
} [5 bytes data]
> GET /videoplayback?id=7a33ded9e6218d1e&itag=137&source=youtube&requiressl=yes&ei=V0knWt3fBIbsowOg1IfgCg&mn=sn-nu5gi0c-npok&mm=31&ms=au&mv=u&pl=43&ratebypass=yes&mime=video/mp4&gir=yes&clen=92139427&lmt=1512416704858018&dur=195.153&signature=329F0B18B27DB4AA9F6F9C8BF58835F8984356C8.FBE391BCB4F0C2A7BEDF79D7635AAD71E92886&mt=1512523703&key=dg_yt0&ip=2406:3000:11:1022:9d80:1845:6e37:751d&ipbits=0&expire=1512545719&sparams=ip,ipbits,expire,id,itag,source,requiressl,ei,mn,mm,ms,mv,pl,ratebypass,mime,gir,clen,lmt,dur HTTP/1.1
> Host: r1---sn-nu5gi0c-npok.googlevideo.com
> User-Agent: curl/7.57.0
> Accept: */*
>
{ [5 bytes data]
< HTTP/1.1 200 OK
< Last-Modified: Mon, 04 Dec 2017 19:45:04 GMT
< Content-Type: video/mp4
< Date: Wed, 06 Dec 2017 01:36:30 GMT
< Expires: Wed, 06 Dec 2017 01:36:30 GMT
< Cache-Control: private, max-age=21229
< Accept-Ranges: bytes
< Content-Length: 92139427
< Connection: close
< Alt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
< X-Content-Type-Options: nosniff
< Server: gvs 1.0
<
{ [5 bytes data]
* Closing connection 0
} [5 bytes data]
* TLSv1.2 (OUT), TLS alert, Client hello (1):
} [2 bytes data]
```

I might be wrong, but I can't see any illegal characters that might cause the URL parsing to fail.

```
$ printf %s "https://r1---sn-nu5gi0c-npok.googlevideo.com/videoplayback?id=7a33ded9e6218d1e&itag=137&source=youtube&requiressl=yes&ei=V0knWt3fBIbsowOg1IfgCg&mn=sn-nu5gi0c-npok&mm=31&ms=au&mv=u&pl=43&ratebypass=yes&mime=video/mp4&gir=yes&clen=92139427&lmt=1512416704858018&dur=195.153&signature=329F0B18B27DB4AA9F6F9C8BF58835F8984356C8.FBE391BCB4F0C2A7BEDF79D7635AAD71E92886&mt=1512523703&key=dg_yt0&ip=2406:3000:11:1022:9d80:1845:6e37:751d&ipbits=0&expire=1512545719&sparams=ip,ipbits,expire,id,itag,source,requiressl,ei,mn,mm,ms,mv,pl,ratebypass,mime,gir,clen,lmt,dur" | xxd
00000000: 6874 7470 733a 2f2f 7231 2d2d 2d73 6e2d  https://r1---sn-
00000010: 6e75 3567 6930 632d 6e70 6f6b 2e67 6f6f  nu5gi0c-npok.goo
00000020: 676c 6576 6964 656f 2e63 6f6d 2f76 6964  glevideo.com/vid
00000030: 656f 706c 6179 6261 636b 3f69 643d 3761  eoplayback?id=7a
00000040: 3333 6465 6439 6536 3231 3864 3165 2669  33ded9e6218d1e&i
00000050: 7461 673d 3133 3726 736f 7572 6365 3d79  tag=137&source=y
00000060: 6f75 7475 6265 2672 6571 7569 7265 7373  outube&requiress
00000070: 6c3d 7965 7326 6569 3d56 306b 6e57 7433  l=yes&ei=V0knWt3
00000080: 6642 4962 736f 774f 6731 4966 6743 6726  fBIbsowOg1IfgCg&
00000090: 6d6e 3d73 6e2d 6e75 3567 6930 632d 6e70  mn=sn-nu5gi0c-np
000000a0: 6f6b 266d 6d3d 3331 266d 733d 6175 266d  ok&mm=31&ms=au&m
000000b0: 763d 7526 706c 3d34 3326 7261 7465 6279  v=u&pl=43&rateby
000000c0: 7061 7373 3d79 6573 266d 696d 653d 7669  pass=yes&mime=vi
000000d0: 6465 6f2f 6d70 3426 6769 723d 7965 7326  deo/mp4&gir=yes&
000000e0: 636c 656e 3d39 3231 3339 3432 3726 6c6d  clen=92139427&lm
000000f0: 743d 3135 3132 3431 3637 3034 3835 3830  t=15124167048580
00000100: 3138 2664 7572 3d31 3935 2e31 3533 2673  18&dur=195.153&s
00000110: 6967 6e61 7475 7265 3d33 3239 4630 4231  ignature=329F0B1
00000120: 3842 3237 4442 3441 4139 4636 4639 4338  8B27DB4AA9F6F9C8
00000130: 4246 3538 3833 3546 3839 3834 3335 3643  BF58835F8984356C
00000140: 382e 4642 4533 3931 4243 4234 4630 4332  8.FBE391BCB4F0C2
00000150: 4137 4245 4446 3739 4437 3633 3541 4144  A7BEDF79D7635AAD
00000160: 3731 4539 3238 3836 266d 743d 3135 3132  71E92886&mt=1512
00000170: 3532 3337 3033 266b 6579 3d64 675f 7974  523703&key=dg_yt
00000180: 3026 6970 3d32 3430 363a 3330 3030 3a31  0&ip=2406:3000:1
00000190: 313a 3130 3232 3a39 6438 303a 3138 3435  1:1022:9d80:1845
000001a0: 3a36 6533 373a 3735 3164 2669 7062 6974  :6e37:751d&ipbit
000001b0: 733d 3026 6578 7069 7265 3d31 3531 3235  s=0&expire=15125
000001c0: 3435 3731 3926 7370 6172 616d 733d 6970  45719&sparams=ip
000001d0: 2c69 7062 6974 732c 6578 7069 7265 2c69  ,ipbits,expire,i
000001e0: 642c 6974 6167 2c73 6f75 7263 652c 7265  d,itag,source,re
000001f0: 7175 6972 6573 736c 2c65 692c 6d6e 2c6d  quiressl,ei,mn,m
00000200: 6d2c 6d73 2c6d 762c 706c 2c72 6174 6562  m,ms,mv,pl,rateb
00000210: 7970 6173 732c 6d69 6d65 2c67 6972 2c63  ypass,mime,gir,c
00000220: 6c65 6e2c 6c6d 742c 6475 72              len,lmt,dur
```