Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

stream assumes all data as UTF-8. That's not always the case. #88

Closed
Ark-kun opened this issue Sep 26, 2018 · 8 comments
Closed

stream assumes all data as UTF-8. That's not always the case. #88

Ark-kun opened this issue Sep 26, 2018 · 8 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle.

Comments

@Ark-kun
Copy link
Contributor

Ark-kun commented Sep 26, 2018

resp = kubernetes.stream.stream(api.connect_get_namespaced_pod_exec, 'sleeping-bash', namespace='default', command=['bash', '-c', 'echo -n -e \\\\xD4'], stderr=True, stdin=False, stdout=True, tty=False)
site-packages\kubernetes\stream\ws_client.py in update(self, timeout)
    176            elif op_code == ABNF.OPCODE_BINARY or op_code == ABNF.OPCODE_TEXT:
    177                data = frame.data
    178                 if six.PY3:
--> 179                     data = data.decode("utf-8")
    180                 if len(data) > 1:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd4 in position 1: unexpected end of data
@whybeyoung
Copy link

the same error here. I solve it by change to data = data.decode("utf-8", "replace")

but. when the file is encode by other charset, this code is not used. any other solutions?

@whybeyoung
Copy link

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Nov 26, 2018
@whybeyoung
Copy link

/sig cluster-lifecycle

@k8s-ci-robot k8s-ci-robot added the sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. label Nov 26, 2018
@roycaihw
Copy link
Member

roycaihw commented Feb 4, 2019

when the file is encode by other charset, this code is not used. any other solutions?

from the rfc we should decode uft8 for OPCODE_TEXT but leave OPCODE_BINARY as raw. this client should not assume encoding for arbitrary binary data

@leavest
Copy link

leavest commented Apr 17, 2019

the same error here. I solve it by change to data = data.decode("utf-8", "replace")

but. when the file is encode by other charset, this code is not used. any other solutions?

I get the same error when use vim command in web terminal.
And I use this code replace.
I haven't found any other coding errors yet

import chardet
data = data.decode(chardet.detect(data).get('encoding') or "utf-8")

@tbarrella
Copy link

15474ef helped to fix the error above, but it seems like this issue should be re-opened with the intent of being able to stream bytes without trying to decode them

@pigletfly
Copy link

/reopen

@k8s-ci-robot
Copy link
Contributor

@pigletfly: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants