Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59854 > unrolled thread

Re: UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: ordinal not in range(128)

Started byFabio Zadrozny <fabiofz@gmail.com>
First post2013-11-18 09:45 -0200
Last post2013-11-18 09:45 -0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: ordinal not in range(128) Fabio Zadrozny <fabiofz@gmail.com> - 2013-11-18 09:45 -0200

#59854 — Re: UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: ordinal not in range(128)

FromFabio Zadrozny <fabiofz@gmail.com>
Date2013-11-18 09:45 -0200
SubjectRe: UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: ordinal not in range(128)
Message-ID<mailman.2836.1384775167.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

On Mon, Nov 18, 2013 at 2:55 AM, Hoàng Tuấn Việt <vietht2@viettel.com.vn>wrote:

> Hi all,
>
>
>
> I use Python telnetlib on Windows 7 32 bit. Here is my code:
>
>
>
>     def *telnet*(*self*, host, os, username, password):
>
>         connection = telnetlib.Telnet(host)
>
>         connection.read_until(*'login: '*)
>
>         connection.write(username + *'\r'*)
>
>         connection.read_until(*'assword: '*)
>
>         connection.write(password + *'\r'*)
>
>         connection.read_until(*'>'*, timeout = TIMEOUT)
>
>        return connection
>
>
>
> I can run the program in Eclipse and telnet successfully to a Windows host.
>
>
>
> But when I export to .exe file:
>
>
>
> from distutils.core import setup
>
> import py2exe
>
>
>
> setup(
>
>     options = {
>
>             *"py2exe"*:{
>
>             *"packages"*: [*'wx.lib.pubsub'*],
>
>             *"dll_excludes"*: [*"MSVCP90.dll"*, *"HID.DLL"*,
> *"w9xpopen.exe"*],
>
>         }
>
>     },
>
>     console = [{*'script'*: *‘my_program.py'*}]
>
> )
>
>
>
> and run the programe, I encounter this error:
>
>
>
> UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0:
> ordinal not in range(128)
>
>
>
> at line:
>
>
>
> connection.write(username + '\r')
>
>
>
> I have debugged and searched the Internet hard but found no solution yet.
>
>
>
> I think it is because of ‘\r’.
>
>
>
> Do you have any idea?
>
>
>
> Viet
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>
You should be able to reproduce the same behavior on PyDev if in your run
configuration you select the encoding of the console to be ascii (run > run
configurations > select run configuration > common > set encoding to
us-ascii).

My guess is that you have the problem because the username has non-ascii
chars -- and you're receiving it as an unicode and not a string... so, you
have to do encode it properly to a string before writing to the connection
(i.e.: username.encode('utf-8') + '\r' -- although the encoding may have to
be a different one and not utf-8).

Cheers,

Fabio

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web