title: Unknown url type error in urllib2
body: <p>I have searched a lot of similar question on SO, but did not find an exact match to my case.</p>
  
  <p>I am trying to download a video using python 2.7</p>
  
  <p>Here is my code for downloading the video</p>
  
  <pre><code>import urllib2
  from bs4 import BeautifulSoup as bs
  
  
  with open('video.txt','r') as f:
      last_downloaded_video = f.read()
  
  webpage = urllib2.urlopen('http://*.net/watch/**-'+last_downloaded_video)
  
  soup = bs(webpage)
  a = []
  for link in soup.find_all('a'):
      if link.has_attr('data-video-id'):
          a.append(link)
  
  #try just with first data-video-id
  
  id = a[0]['data-video-id']
  webpage2 = urllib2.urlopen('http://*/video/play/'+id)
  soup = bs(webpage2)
  string = str(soup.find_all('script')[2])
  print string
  url = string.split(': ')[1].split(',')[0]
  url = url.replace('"','')
  print url
  print type(url)
  
  video = urllib2.urlopen(url).read()
  filename = "video.mp4"
  with open(filename,'wb') as f:
      f.write(video)
  </code></pre>
  
  <p>This code gives an unknown url type error. The traceback is </p>
  
  <pre><code>Traceback (most recent call last):
    File "naruto.py", line 26, in &lt;module&gt;
      video = urllib2.urlopen(url).read()
    File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
      return _opener.open(url, data, timeout)
    File "/usr/lib/python2.7/urllib2.py", line 404, in open
      response = self._open(req, data)
    File "/usr/lib/python2.7/urllib2.py", line 427, in _open
      'unknown_open', req)
    File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
      result = func(*args)
    File "/usr/lib/python2.7/urllib2.py", line 1247, in unknown_open
      raise URLError('unknown url type: %s' % type)
  urllib2.URLError: &lt;urlopen error unknown url type: 'http&gt;
  </code></pre>
  
  <p>However, when i store the same url in a variable and attempt to download it from terminal, no error is shown.
  I am confused as to what the problem is.
  I got a similar question <a href="https://mail.python.org/pipermail/python-list/2009-June/539695.html" rel="nofollow">in python mailing list</a></p>