Skip to content

AttributeError: 'FakeOutput' object has no attribute 'encoding' #622

Closed

Description

@goetzc

sys.stdout.encoding gives this error.
Also sys.stdin.encoding gives 'UTF8', while python gives 'UTF-8' for both cases.

This commit makes bpython work (naturally stdin is still different than in standard python):

bpython version 0.15 on top of Python 3.5.2 /usr/bin/python
>>> import sys
>>> sys.stdin.encoding
'UTF8'
>>> sys.stdout.encoding
'UTF-8'

Activity

  1. thomasballinger commented on Jul 29, 2016

    @thomasballinger
    Member

    Hm, I guess this should just be a property that returns whatever sys.stdout.encoding is, since that's how strings are actually being decoded. What are you using this for? (asking to try to understand if this is the right solution)

  2. goetzc commented on Jul 29, 2016

    @goetzc
    Author

    I guess this should just be a property that returns whatever sys.stdout.encoding is

    This is a much better solution!

    What are you using this for?

    I don't remember that :D

  3. goetzc commented on Jul 30, 2016

    @goetzc
    Author

    I found another AttributeError for 'FakeOutput', this time for 'fileno'. I was using PyQtGraph. Issue #628.

  4. thomasballinger commented on Aug 5, 2016

    @thomasballinger
    Member

    Proposed solution in #629

  5. gerryjenkinslb commented on Dec 16, 2017

    @gerryjenkinslb

    I ran into the problem in bpython import as well.
    I would look at what idle does in its code base:
    see cpython run.py PseudoFile class for example. if FakeOutput only encodes 'utf-8' then just return that.

  6. rpdelaney commented on Mar 14, 2019

    @rpdelaney

    Here's my +1:

    $ python3
    Python 3.7.2 (default, Feb 12 2019, 08:16:38) 
    [Clang 10.0.0 (clang-1000.11.45.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pipenv
    >>> 
    $ bpython
    bpython version 0.17.1 on top of Python 3.7.2 /usr/local/opt/python/bin/python3.7
    >>> import pipenv
    Traceback (most recent call last):
      File "<input>", line 1, in <module>
        import pipenv
      File "/Users/ryan.delaney/Library/Python/3.7/lib/python/site-packages/pipenv/__init__.py", line 47, in <module>
        from .cli import cli
      File "/Users/ryan.delaney/Library/Python/3.7/lib/python/site-packages/pipenv/cli/__init__.py", line 3, in <module>
        from .command import cli
      File "/Users/ryan.delaney/Library/Python/3.7/lib/python/site-packages/pipenv/cli/command.py", line 19, in <module>
        from .options import (
      File "/Users/ryan.delaney/Library/Python/3.7/lib/python/site-packages/pipenv/cli/options.py", line 11, in <module>
        from .. import environments
      File "/Users/ryan.delaney/Library/Python/3.7/lib/python/site-packages/pipenv/environments.py", line 7, in <module>
        from ._compat import fix_utf8
      File "/Users/ryan.delaney/Library/Python/3.7/lib/python/site-packages/pipenv/_compat.py", line 96, in <module>
        OUT_ENCODING, ERR_ENCODING = force_encoding()
      File "/Users/ryan.delaney/Library/Python/3.7/lib/python/site-packages/pipenv/_compat.py", line 60, in force_encoding
        stdout_encoding = sys.stdout.encoding
    AttributeError: 'FakeOutput' object has no attribute 'encoding'
    >>> 
    
  7. tiffanyb commented on Jun 13, 2020

    @tiffanyb

    The encoding issue exists in bpython 0.19 and Python 3.8.0

    $ bpython
    bpython version 0.19 on top of Python 3.8.0
    >>> import sys
    >>> sys.stdout.encoding
    Traceback (most recent call last):
      File "<input>", line 1, in <module>
        sys.stdout.encoding
    AttributeError: 'FakeOutput' object has no attribute 'encoding'
    `
    
  8. alisianoi commented on Aug 17, 2020

    @alisianoi

    The encoding issue still exists in bpython 0.19 and Python 3.8.2, my use case is Z3 solver:

    >>> from z3 import *
    >>> Tie, Shirt = Bools('Tie Shirt')
    >>> s = Solver()
    >>> s.add(Or(Tie, Shirt), Or(Not(Tie), Shirt), Or(Not(Shirt), Not(Tie)))
    >>> s.check()
    sat
    >>> s.model()
    Traceback (most recent call last):
    

    The Z3 example comes from here: https://theory.stanford.edu/~nikolaj/programmingz3.html#sec-logical-interface

  9. deadeert commented on Sep 7, 2020

    @deadeert

    Hello, I confim @alisianoi I have the same issue with python 3.8.5 and bpython 0.19.

  10. itsfarseen commented on Sep 28, 2020

    @itsfarseen

    I was trying to use Z3 and is affected by this.
    I am using this as a workaround:

    sys.stdout.encoding='utf-8'
  11. sebastinas commented on Oct 11, 2020

    @sebastinas
    Contributor

    Fixes by #629.

  12. added this to the release-0.20 milestone on Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions