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

youtube-dl fails with python version >= 3.2 #697

Closed
okurz opened this issue Feb 21, 2013 · 4 comments
Closed

youtube-dl fails with python version >= 3.2 #697

okurz opened this issue Feb 21, 2013 · 4 comments

Comments

@okurz
Copy link

@okurz okurz commented Feb 21, 2013

error description

When executing youtube-dl on arch linux using python 3.3 I get the error message:

$ youtube-dl -u <username> -p <password> --title http://www.youtube.com/playlist?list=<list_id>
[youtube] PL <list_id>: Downloading page #1
[youtube] PL <list_id>: Found 3 videos
[youtube] Setting language
[youtube] Logging in
Traceback (most recent call last):
  File "/usr/bin/youtube-dl", line 6, in <module>
    youtube_dl.main()
  File "/usr/lib/python3.3/site-packages/youtube_dl/__init__.py", line 512, in main
    _real_main()
  File "/usr/lib/python3.3/site-packages/youtube_dl/__init__.py", line 496, in _real_main
    retcode = fd.download(all_urls)
  File "/usr/lib/python3.3/site-packages/youtube_dl/FileDownloader.py", line 505, in download
    videos = ie.extract(url)
  File "/usr/lib/python3.3/site-packages/youtube_dl/InfoExtractors.py", line 93, in extract
    return self._real_extract(url)
  File "/usr/lib/python3.3/site-packages/youtube_dl/InfoExtractors.py", line 1690, in _real_extract
    self._downloader.download(['http://www.youtube.com/watch?v=%s' % id])
  File "/usr/lib/python3.3/site-packages/youtube_dl/FileDownloader.py", line 505, in download
    videos = ie.extract(url)
  File "/usr/lib/python3.3/site-packages/youtube_dl/InfoExtractors.py", line 92, in extract
    self.initialize()
  File "/usr/lib/python3.3/site-packages/youtube_dl/InfoExtractors.py", line 87, in initialize
    self._real_initialize()
  File "/usr/lib/python3.3/site-packages/youtube_dl/InfoExtractors.py", line 329, in _real_initialize
    login_results = compat_urllib_request.urlopen(request).read().decode('utf-8')
  File "/usr/lib/python3.3/urllib/request.py", line 160, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.3/urllib/request.py", line 471, in open
    req = meth(req)
  File "/usr/lib/python3.3/urllib/request.py", line 1183, in do_request_
    raise TypeError(msg)
            compat_urllib_request.urlopen(request).read()
        except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
            self._downloader.to_stderr(u'WARNING: unable to set language: %s' % compat_str(err))
TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.

proposed solution

This change should fix the issue:

--- /tmp/InfoExtractors.py.old  2013-02-21 15:48:21.891371538 +0100
+++ /tmp/InfoExtractors.py  2013-02-21 15:48:27.448074643 +0100
@@ -323,7 +323,8 @@
                 'username': username,
                 'password': password,
                 }
-        request = compat_urllib_request.Request(self._LOGIN_URL, compat_urllib_parse.urlencode(login_form))
+        data = compat_urllib_parse.urlencode(login_form).encode('utf-8')
+        request = compat_urllib_request.Request(self._LOGIN_URL, data)
         try:
             self.report_login()
             login_results = compat_urllib_request.urlopen(request).read().decode('utf-8')

references

According to http://stackoverflow.com/questions/5440485/typeerror-post-data-should-be-bytes-or-an-iterable-of-bytes-it-cannot-be-str
this happens since python >= 3.2

@phihag
Copy link
Contributor

@phihag phihag commented Feb 21, 2013

Sorry, I can't reproduce the error, and the patch is out of date. Which version of youtube-dl are you using? Does the problem persist if you update with

sudo youtube-dl -U

?

@arararar
Copy link

@arararar arararar commented Feb 28, 2013

I have problems in the last time with youtube-dl -U
COuld have to do with python too.

(Ubuntu 12.04)

Errors:

youtube-dl --update
Updating to latest version...
Traceback (most recent call last):
File "/usr/bin/youtube-dl", line 4645, in
main()
File "/usr/bin/youtube-dl", line 4636, in main
_real_main()
File "/usr/bin/youtube-dl", line 4610, in _real_main
updateSelf(fd, sys.argv[0])
File "/usr/bin/youtube-dl", line 4203, in updateSelf
urlh.close()
UnboundLocalError: local variable 'urlh' referenced before assignment

@phihag
Copy link
Contributor

@phihag phihag commented Mar 1, 2013

@arararar That's a completely different issue, please open a new one. The following should fix your problem though:

wget http://youtube-dl.org/downloads/2013.02.25/youtube-dl -O "$(which youtube-dl)"
sudo youtube-dl -U
@phihag
Copy link
Contributor

@phihag phihag commented Mar 1, 2013

I'm closing this issue since the error should have been solved by the recent changes. If it hasn't, please comment or open a new issue. Thanks!

@phihag phihag closed this Mar 1, 2013
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
3 participants
You can’t perform that action at this time.