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

UnicodeDecodeError with method read_namespaced_pod_log() #2118

Closed
berqavos opened this issue Sep 6, 2023 · 8 comments
Closed

UnicodeDecodeError with method read_namespaced_pod_log() #2118

berqavos opened this issue Sep 6, 2023 · 8 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@berqavos
Copy link

berqavos commented Sep 6, 2023

What happened (please include outputs or screenshots):
While using the following pod_logs = v1.read_namespaced_pod_log(name=pod_name, namespace=namespace). I receive the error:

File "/opt/app/batch/python_virt/venv_app/lib64/python3.11/site-packages/kubernetes/client/rest.py", line 229, in request
    r.data = r.data.decode('utf8')
             ^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 3793: invalid continuation byte

What you expected to happen:
The pod logs are displayed correctly.

How to reproduce it (as minimally and precisely as possible):
Use pods where the output is not utf-8. In my case it's latin-1.

Anything else we need to know?:
There are legacy applications where the output has to be in a special charset. Therefore, it would be great when the method read_namespaced_pod_log from the kubernetes.client.CoreV1Api() could have a parameter charset, where the developer can choose a desired charset. For example:
pod_logs = v1.read_namespaced_pod_log(name=pod_name, namespace=namespace, charset='latin1')

As stated above at the moment the charset utf-8 is hardcoded in:

r.data = r.data.decode('utf8')

It worked as soon as I changed r.data = r.data.decode('utf8') to r.data = r.data.decode('latin1')

Environment:

  • Kubernetes version: 1.26
  • OS: Fedora 38
  • Python version: 3.11.4
  • Python client version: 26.1.0
@berqavos berqavos added the kind/bug Categorizes issue or PR as related to a bug. label Sep 6, 2023
@roycaihw
Copy link
Member

/assign @yliaog

@yliaog
Copy link
Contributor

yliaog commented Sep 11, 2023

#2100

seems to be similar issue

@yliaog
Copy link
Contributor

yliaog commented Sep 11, 2023

agreed it's better to support more charset, but python/kubernetes/client/rest.py is generated by openapi generator, so the support needs to be added there.

@TheLord45
Copy link

I had the same problem and applying the above solution worked. So I modified the code a little bit and added a function to allow setting the character set for the client. I attached the diff here.
kubernetes.txt

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 28, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 27, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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.

@k8s-ci-robot k8s-ci-robot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

6 participants