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

codecs.StreamReader doesn't work with nonblocking streams: TypeError: can't concat bytes to NoneType #68748

Closed
yac mannequin opened this issue Jul 3, 2015 · 4 comments
Labels

Comments

@yac
Copy link
Mannequin

yac mannequin commented Jul 3, 2015

BPO 24560
Nosy @vstinner, @ezio-melotti
Superseder
  • bpo-13322: The io module doesn't support non-blocking files
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-10-10.08:29:35.445>
    created_at = <Date 2015-07-03.15:12:04.370>
    labels = ['3.7', 'expert-unicode']
    title = "codecs.StreamReader doesn't work with nonblocking streams: TypeError: can't concat bytes to NoneType"
    updated_at = <Date 2019-10-10.08:29:35.441>
    user = 'https://bugs.python.org/yac'

    bugs.python.org fields:

    activity = <Date 2019-10-10.08:29:35.441>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-10-10.08:29:35.445>
    closer = 'vstinner'
    components = ['Unicode']
    creation = <Date 2015-07-03.15:12:04.370>
    creator = 'yac'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 24560
    keywords = []
    message_count = 4.0
    messages = ['246186', '246261', '354298', '354340']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'ezio.melotti', 'yac', 'Fritz Reese']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '13322'
    type = None
    url = 'https://bugs.python.org/issue24560'
    versions = ['Python 3.4', 'Python 3.7']

    @yac
    Copy link
    Mannequin Author

    yac mannequin commented Jul 3, 2015

    File "/usr/lib64/python3.4/codecs.py", line 490, in read
    data = self.bytebuffer + newdata
    TypeError: can't concat bytes to NoneType

                if size < 0:
                    newdata = self.stream.read()
                else:
                    newdata = self.stream.read(size)
                # decode bytes (those remaining from the last call included)
                data = self.bytebuffer + newdata

    if self.stream is nonblocking, it's read will return None (py3, py2 raises IOError(EGAIN)).

    Simple if newdata is None: return None should fix that I guess

    @yac yac mannequin added the topic-unicode label Jul 3, 2015
    @vstinner
    Copy link
    Member

    vstinner commented Jul 4, 2015

    Use the io module instead using the open() function.

    @FritzReese
    Copy link
    Mannequin

    FritzReese mannequin commented Oct 9, 2019

    This is still an issue on Linux in both 3.4 and 3.7 even when using io.open() as suggested by @vstinner:

    >>> import io, os, fcntl
    >>> r, w = os.pipe()
    >>> fcntl(r, fcntl.F_SETFL, os.O_NONBLOCK)
    0
    >>> stream = io.open(r, 'rt')
    >>> stream
    <_io.TextIOWrapper name=X mode='rt' encoding='UTF-8'>
    >>> stream.buffer
    <_io.BufferedReader name=X>
    >>> print(repr(stream.buffer.read()))
    None
    >>> stream.read()
    Traceback (most recent call last):
      ...
      File ".../python3.7/codecs.py"..., in decode
        data = self.buffer + input
    TypeError: can't concat NoneType to bytes

    The error is present in at least 3.4 up to 3.7 where the underlying buffer.read() returns None which is not handled by the TextIOStream.

    @FritzReese FritzReese mannequin added the 3.7 (EOL) end of life label Oct 9, 2019
    @vstinner
    Copy link
    Member

    I close this issue as a duplicate of bpo-13322.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant