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: 'utf-8' codec can't decode bytes in position 4093-4094: unexpected end of data #42

Closed
messense opened this issue Dec 8, 2021 · 5 comments · Fixed by #44

Comments

@messense
Copy link
Collaborator

messense commented Dec 8, 2021

CRI [20211208-07:42:34.995] thr=140672309044992 lobbyboy.socket_handle:254: *** Socket thread error.                                                                                                                                                                                                                          Traceback (most recent call last):
  File "/root/code/lobbyboy/lobbyboy/socket_handle.py", line 247, in run
    self.user_using(server, proxy_subprocess)
  File "/root/code/lobbyboy/lobbyboy/socket_handle.py", line 188, in user_using
    send_to_channel(self.channel, os.read(master_fd, 10240).decode(), suffix="")
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 4093-4094: unexpected end of data
DEB [20211208-07:42:35.003] thr=140672300570368 paramiko.transport:1819: EOF in transport thread
@messense
Copy link
Collaborator Author

messense commented Dec 8, 2021

def send_to_channel(channel: Channel, msg: str = "", prefix: str = "", suffix: str = "\r\n"):
if isinstance(msg, bytes):
msg = msg.decode()
channel.send(f"{prefix or ''}{msg}{suffix or ''}".encode())

decode and encode again...that's a mess.

@luxiaba
Copy link
Collaborator

luxiaba commented Dec 8, 2021

yes it was a bit. in order to be compatible with others at that time, i'll check and unify soon, thank you for pointing this out.

@messense
Copy link
Collaborator Author

messense commented Dec 8, 2021

BTW, I think using channel.send is wrong since it doesn't guarantee that the buffer will be sent fully, sendall should be used instead. It's a common mistake in networking code.

Applications are responsible for checking that all data has been sent: if only some of the data was transmitted, the application needs to attempt delivery of the remaining data.

@luxiaba
Copy link
Collaborator

luxiaba commented Dec 8, 2021

seems channel.sendall is right, @laixintao what do you think?

@laixintao
Copy link
Collaborator

Yes, should use channel.sendall (my bad).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants