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

Python3 write_channel "Can't convert 'bytes' object to str implicitly" #151

Closed
hdimitriou opened this issue Aug 2, 2019 · 14 comments
Closed
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.

Comments

@hdimitriou
Copy link

I am using the rundeck kubernetes plugin to execute a script to a pod and I get the following error

15:53:46 | Traceback (most recent call last):
-- | --
15:53:46 | File "/home/rundeck/libext/cache/kubernetes-plugin-1.10.1-SNAPSHOT/pods-copy-file.py", line 69, in <module>
15:53:46 | main()
15:53:46 | File "/home/rundeck/libext/cache/kubernetes-plugin-1.10.1-SNAPSHOT/pods-copy-file.py", line 65, in main
15:53:46 | common.copy_file(name, namespace, container, source_file, destination_path, destination_file_name)
15:53:46 | File "/home/rundeck/libext/cache/kubernetes-plugin-1.10.1-SNAPSHOT/common.py", line 396, in copy_file
15:53:46 | resp.write_stdin(c)
15:53:46 | File "/usr/local/lib/python3.5/dist-packages/kubernetes/stream/ws_client.py", line 160, in write_stdin
15:53:46 | self.write_channel(STDIN_CHANNEL, data)
15:53:46 | File "/usr/local/lib/python3.5/dist-packages/kubernetes/stream/ws_client.py", line 114, in write_channel
15:53:46 | self.sock.send(chr(channel) + data)
15:53:46 | TypeError: Can't convert 'bytes' object to str implicitly

On this comment there is a workaround - a change to ws_client.py

def write_channel(self, channel, data):
    """Write data to a channel."""
    self.sock.send(bytes(chr(channel), 'utf-8') + data)

This worked for me, so maybe someone with more knowledge can see if it should be merged fixed this way, or there's something better

I am using 'Python 3.5.2' and I tried kubernetes 9.0.0 and 10.0.0
This issue does not happen with Python2.7

@roycaihw
Copy link
Member

roycaihw commented Aug 6, 2019

/assign

@roycaihw
Copy link
Member

roycaihw commented Aug 7, 2019

The ws client we use OPCODE_TEXT by default, which accepts utf-8 string or unicode as payload https://github.com/websocket-client/websocket-client/blob/66081be8e0523c9dfaffcb18ba1c8e4765e2288e/websocket/_core.py#L241-L253.

I think the error means that we don't support bytes payload yet. One fix could be supporting the opcode parameter in our client and do the bytes(chr(channel), 'utf-8') conversion when necessary, but we need to test that

I will work on this when I get time, but in the meantime feel free to jump in if anyone is interested.

/help

@k8s-ci-robot
Copy link
Contributor

@roycaihw:
This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

The ws client we use OPCODE_TEXT by default, which accepts utf-8 string or unicode as payload https://github.com/websocket-client/websocket-client/blob/66081be8e0523c9dfaffcb18ba1c8e4765e2288e/websocket/_core.py#L241-L253.

I think the error means that we don't support bytes payload yet. One fix could be supporting the opcode parameter in our client and do the bytes(chr(channel), 'utf-8') conversion when necessary, but we need to test that

I will work on this when I get time, but in the meantime feel free to jump in if anyone is interested.

/help

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 added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Aug 7, 2019
@sergei-maertens
Copy link
Contributor

I'll give this a stab

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/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 Nov 12, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/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 Dec 12, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

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.

@Ark-kun
Copy link
Contributor

Ark-kun commented Feb 11, 2020

I'm not sure this issue is fixed.
/reopen

@k8s-ci-robot
Copy link
Contributor

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

In response to this:

I'm not sure this issue is fixed.
/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.

@roycaihw
Copy link
Member

roycaihw commented Feb 11, 2020

/reopen
/remove-lifecycle rotten
/unassign

This issue still exists. #152 is a great potential fix for it

@k8s-ci-robot
Copy link
Contributor

@roycaihw: Reopened this issue.

In response to this:

/reopen
/remove-lifecycle rotten
/unassign

This issue still exists

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 reopened this Feb 11, 2020
@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Feb 11, 2020
k8s-ci-robot added a commit that referenced this issue Feb 14, 2020
Refs. #151 -- detect binary payloads and send the correct opcode
@roycaihw
Copy link
Member

Fixed by #152

/close

@k8s-ci-robot
Copy link
Contributor

@roycaihw: Closing this issue.

In response to this:

Fixed by #152

/close

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
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
Projects
None yet
Development

No branches or pull requests

6 participants