Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.
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

Description

@hdimitriou

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

Activity

  1. roycaihw commented on Aug 6, 2019

    @roycaihw
    Member

    /assign

  2. roycaihw commented on Aug 7, 2019

    @roycaihw
    Member

    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

  3. k8s-ci-robot commented on Aug 7, 2019

    @k8s-ci-robot
    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.

    Details

    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.

  4. added
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    on Aug 7, 2019
  5. sergei-maertens commented on Aug 14, 2019

    @sergei-maertens
    Contributor

    I'll give this a stab

  6. fejta-bot commented on Nov 12, 2019

    @fejta-bot

    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

  7. added
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Nov 12, 2019
  8. fejta-bot commented on Dec 12, 2019

    @fejta-bot

    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

  9. added
    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.
    and removed
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Dec 12, 2019
  10. fejta-bot commented on Jan 11, 2020

    @fejta-bot

    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

  11. k8s-ci-robot commented on Jan 11, 2020

    @k8s-ci-robot
    Contributor

    @fejta-bot: Closing this issue.

    Details

    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.

  12. Ark-kun commented on Feb 11, 2020

    @Ark-kun
    Contributor

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

  13. k8s-ci-robot commented on Feb 11, 2020

    @k8s-ci-robot
    Contributor

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

    Details

    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.

  14. roycaihw commented on Feb 11, 2020

    @roycaihw
    Member

    /reopen
    /remove-lifecycle rotten
    /unassign

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

  15. k8s-ci-robot commented on Feb 11, 2020

    @k8s-ci-robot
    Contributor

    @roycaihw: Reopened this issue.

    Details

    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.

  16. removed
    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.
    on Feb 11, 2020
  17. added a commit that references this issue on Feb 14, 2020
  18. roycaihw commented on Feb 14, 2020

    @roycaihw
    Member

    Fixed by #152

    /close

  19. k8s-ci-robot commented on Feb 14, 2020

    @k8s-ci-robot
    Contributor

    @roycaihw: Closing this issue.

    Details

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions