HTTP错误403:尝试使用Pafy下载YouTube视频时被禁止

时间:2015-01-23 09:12:27

标签: python-2.7 video youtube youtube-api pafy

    hdr = {'User-Agent': 'Mozilla/5.0'}
    url = "https://www.youtube.com/results?search_query=%s+%s" % (artistName, songName)
    req = urllib2.Request(url, headers=hdr)
    page = urllib2.urlopen(req)
    soup = BeautifulSoup(page)
    for SongTitle in soup.findAll('a', {'class': 'yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-sessionlink     spf-link '}):
        song_titles.append(SongTitle.string)
        i += 1

所以这是我用来搜索带有自定义网址的YouTube页面的代码。之后,用户可以根据视频号码选择要下载的视频。 问题是,我尝试下载的大多数视频都会返回以下错误:

WARNING:root:ciphertag doesn't match signature type
WARNING:root:JRMOMjCoR58
Traceback (most recent call last):
  File "PyKo.py", line 123, in <module>
    query(sys.argv[1], sys.argv[2])
  File "PyKo.py", line 118, in query
    downloadSong(link_to_download, s_url)
  File "PyKo.py", line 30, in downloadSong
    video = pafy.new(url)
  File "C:\Python27\lib\site-packages\pafy\pafy.py", line 138, in new
    return Pafy(url, basic, gdata, signature, size, callback)
  File "C:\Python27\lib\site-packages\pafy\pafy.py", line 1041, in __init__
    self.fetch_basic()
  File "C:\Python27\lib\site-packages\pafy\pafy.py", line 1087, in fetch_basic
    self.dash = _extract_dash(self._dashurl)
  File "C:\Python27\lib\site-packages\pafy\pafy.py", line 274, in _extract_dash
    dashdata = fetch_decode(dashurl)
  File "C:\Python27\lib\site-packages\pafy\pafy.py", line 91, in fetch_decode
    req = g.opener.open(url)
  File "C:\Python27\lib\urllib2.py", line 410, in open
    response = meth(req, response)
  File "C:\Python27\lib\urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python27\lib\urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden

只有非常少量的视频才有效。 我已经用Google搜索并找到类似的东西的答案,它说插入一个标题,所以我做了但它仍然无法正常工作。 提前谢谢!

0 个答案:

没有答案