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

sys.stderr does not always have an attribute isatty() #16659

Closed
NightMachinary opened this issue Jun 6, 2018 · 4 comments
Closed

sys.stderr does not always have an attribute isatty() #16659

NightMachinary opened this issue Jun 6, 2018 · 4 comments
Labels

Comments

@NightMachinary
Copy link

@NightMachinary NightMachinary commented Jun 6, 2018

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

  • [x ] I've verified and I assure that I'm running youtube-dl 2018.06.04

Before submitting an issue make sure you have:

  • [ x] At least skimmed through the README, most notably the FAQ and BUGS sections
  • [ x] Searched the bugtracker for similar issues including closed ones
  • [x ] Checked that provided video/audio/playlist URLs (if any) are alive and playable in a browser

What is the purpose of your issue?

  • [ x] 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

Traceback (most recent call last):
  File "/home/mary/code/little-mary/src/puker.py", line 133, in basic_res
    d2 = ydl.extract_info(url)
  File "/home/mary/miniconda3/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 792, in extract_info
    ie_result = ie.extract(url)
  File "/home/mary/miniconda3/lib/python3.6/site-packages/youtube_dl/extractor/common.py", line 500, in extract
    ie_result = self._real_extract(url)
  File "/home/mary/miniconda3/lib/python3.6/site-packages/youtube_dl/extractor/youtube.py", line 1545, in _real_extract
    ytplayer_config = self._get_ytplayer_config(video_id, video_webpage)
  File "/home/mary/miniconda3/lib/python3.6/site-packages/youtube_dl/extractor/youtube.py", line 1256, in _get_ytplayer_config
    patterns, webpage, 'ytplayer.config', default=None)
  File "/home/mary/miniconda3/lib/python3.6/site-packages/youtube_dl/extractor/common.py", line 866, in _search_regex
    if not self._downloader.params.get('no_color') and compat_os_name != 'nt' and sys.stderr.isatty():
AttributeError: '_StdoutProxy' object has no attribute 'isatty'

I even have the quiet mode activated. You should add something like hasattr(sys.stdout, "isatty") there.
BTW, this problem arises only when I run the script via iPython in an SSH session. I guess the SSH terminal is 'weak'? If so, can't I just somehow make it fake a more powerful terminal?

@NightMachinary
Copy link
Author

@NightMachinary NightMachinary commented Jun 6, 2018

I tried the following workaround but it didn't work:

class PseudoTTY(object):
    def __init__(self, underlying):
        self.__underlying = underlying
    def __getattr__(self, name):
        return getattr(self.__underlying, name)
    def isatty(self):
        return True

sys.stdout = PseudoTTY(sys.stdout)
sys.stderr = PseudoTTY(sys.stderr)

When I call sys.stderr.isatty(), it returns True, but it seems youtube-dl is somehow bypassing my intervention.

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jun 8, 2018

Something in your setup patches sys.stderr with nonconforming implementation lacking isatty. Googling for _StdoutProxy brings to prompt toolkit.

@dstftw dstftw closed this Jun 8, 2018
@dstftw dstftw added the external-bugs label Jun 8, 2018
@NightMachinary
Copy link
Author

@NightMachinary NightMachinary commented Jun 8, 2018

@min050820
Copy link

@min050820 min050820 commented Jun 18, 2019

Quoted from Python 2.7 official documentation:

stdout and stderr needn’t be built-in file objects: any object is acceptable as long as it has a write() method that takes a string argument.

This buf effects some advanced GUI programs that redirect sys.stdout to somewhere else. The code really should check hasattr. Or, at least, have a try~except statement.

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.