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

UnicodeWarning on Python 2 with non-ASCII URLs in HTTP redirection #9588

Closed
yan12125 opened this issue May 23, 2016 · 1 comment
Closed

UnicodeWarning on Python 2 with non-ASCII URLs in HTTP redirection #9588

yan12125 opened this issue May 23, 2016 · 1 comment
Assignees
Labels
bug

Comments

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 23, 2016

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 that [x])
  • Use Preview tab to see how your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2016.05.21.2. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2016.05.21.2

Before submitting an issue make sure you have:

  • At least skimmed through README and most notably FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • 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

Description of your issue, suggested solution and other information

Originally reported at efbed08#commitcomment-17573052.

On Python 2, Location header is a bytes-like object, while escape_url always return a unicode object. As a result, an UnicodeWarning may occur:

$ python2 -W error youtube_dl/__main__.py -vF http://lifenews.ru/news/98736
[debug] System config: []
[debug] User config: []
[debug] Command-line args: [u'-vF', u'http://lifenews.ru/news/98736']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2016.05.21.2
[debug] Git HEAD: 78d3b3e
[debug] Python version 2.7.11 - Linux-4.5.1-1-ARCH-x86_64-with-glibc2.2.5
[debug] exe versions: ffmpeg 3.0.2, ffprobe 3.0.2, rtmpdump 2.4
[debug] Proxy map: {}
[lifenews] 98736: Downloading page
Traceback (most recent call last):
  File "youtube_dl/__main__.py", line 19, in <module>
    youtube_dl.main()
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/__init__.py", line 421, in main
    _real_main(argv)
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/__init__.py", line 411, in _real_main
    retcode = ydl.download(all_urls)
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/YoutubeDL.py", line 1736, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/YoutubeDL.py", line 676, in extract_info
    ie_result = ie.extract(url)
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/extractor/common.py", line 341, in extract
    return self._real_extract(url)
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/extractor/lifenews.py", line 84, in _real_extract
    video_id, 'Downloading page')
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/extractor/common.py", line 501, in _download_webpage
    res = self._download_webpage_handle(url_or_request, video_id, note, errnote, fatal, encoding=encoding, data=data, headers=headers, query=query)
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/extractor/common.py", line 408, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query)
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/extractor/common.py", line 388, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/YoutubeDL.py", line 1946, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/usr/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/home/yen/Executables/Multimedia/youtube-dl/youtube_dl/utils.py", line 865, in http_response
    if location != location_escaped:
UnicodeWarning: Unicode unequal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
@yan12125 yan12125 added the bug label May 23, 2016
@yan12125 yan12125 self-assigned this May 23, 2016
yan12125 referenced this issue May 23, 2016
With IDN (Internationalized Domain Name) and a proxy, non-ascii URLs
are passed down to urllib/urllib2, causing UnicodeEncodeError

Fixes #8890
yan12125 added a commit that referenced this issue Jun 2, 2016
@yan12125
Copy link
Collaborator Author

@yan12125 yan12125 commented Jun 2, 2016

Fixed as #9604 pushed to master.

@yan12125 yan12125 closed this Jun 2, 2016
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
1 participant
You can’t perform that action at this time.