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

ytsearch fail with TypeError: can't use a string pattern on a bytes-like object (JSON problem) #706

Closed
joksnet opened this issue Feb 23, 2013 · 2 comments

Comments

@joksnet
Copy link
Contributor

@joksnet joksnet commented Feb 23, 2013

I don't known if it's a JSON error, or it's just that youtube-dl don't decode the bytes from the query.

$ python -m youtube_dl --verbose "ytsearch:Los Autenticos Decadentes Tu forma de ser"
[debug] youtube-dl version 2012.02.22
[debug] Git HEAD: 4be0aa3
[debug] Python version 3.3.0 - Linux-3.7.7-1-ARCH-x86_64-with-arch
[debug] Proxy map: {}
[youtube] query "Los Autenticos Decadentes Tu forma de ser": Downloading page 1
Traceback (most recent call last):
  File "/usr/lib/python3.3/runpy.py", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python3.3/runpy.py", line 73, in _run_code
    exec(code, run_globals)
  File "./youtube_dl/__main__.py", line 17, in <module>
    youtube_dl.main()
  File "./youtube_dl/__init__.py", line 516, in main
    _real_main()
  File "./youtube_dl/__init__.py", line 500, in _real_main
    retcode = fd.download(all_urls)
  File "./youtube_dl/FileDownloader.py", line 507, in download
    videos = ie.extract(url)
  File "./youtube_dl/InfoExtractors.py", line 93, in extract
    return self._real_extract(url)
  File "./youtube_dl/InfoExtractors.py", line 1443, in _real_extract
    self._download_n_results(query, 1)
  File "./youtube_dl/InfoExtractors.py", line 1479, in _download_n_results
    api_response = json.loads(data)['data']
  File "/usr/lib/python3.3/json/__init__.py", line 309, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.3/json/decoder.py", line 352, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: can't use a string pattern on a bytes-like object
@joksnet
Copy link
Contributor Author

@joksnet joksnet commented Feb 23, 2013

Seems like this fix the problem:

--- a/youtube_dl/InfoExtractors.py
+++ b/youtube_dl/InfoExtractors.py
@@ -1472,7 +1472,7 @@ class YoutubeSearchIE(InfoExtractor):
             result_url = self._API_URL % (compat_urllib_parse.quote_plus(query), (50*pagenum)+1)
             request = compat_urllib_request.Request(result_url)
             try:
-                data = compat_urllib_request.urlopen(request).read()
+                data = compat_urllib_request.urlopen(request).read().decode('utf-8')
             except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
                 self._downloader.trouble(u'ERROR: unable to download API page: %s' % compat_str(err))
                 return
@phihag
Copy link
Contributor

@phihag phihag commented Feb 24, 2013

Discussed in #707.

@phihag phihag closed this Feb 24, 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
2 participants
You can’t perform that action at this time.