paramiko cannot send unicode strings to stdin of applicatons

Bug #1186648 reported by Florian Streibelt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
paramiko
Invalid
Undecided
Unassigned

Bug Description

The Problem occurs when doing
    data=u"mööp!"
    chan.exec_command(command)
    chan.sendall(data)

This crashes in paramiko/message.py in add_string, line 259:
        self.add_int(len(s))
        self.packet.write(s)
        return self

UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-2: ordinal not in range(128)

I guess its due to paramiko using cStringIO to internally store data.

from http://docs.python.org/2/library/stringio.html

"Unlike the StringIO module, this module is not able to accept Unicode strings that cannot be encoded as plain ASCII strings."

This leads to a problem when you want to store Unicode Strings:

import cStringIO
packet = cStringIO.StringIO()
packet.write(u"mööp!")
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-13-4874a3de93fc> in <module>()
----> 1 packet.write(u"mööp!")

Am I missing something obvious like manually encoding the unicode to bytes?

Revision history for this message
Florian Streibelt (mutax) wrote :

of _course_ I was missing something after 2 days without sleep:

data= u"mööp".encode('utf-8')

works.

Changed in paramiko:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.