Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59854
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <fabiofz@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'skip:[ 20': 0.04; 'yet.': 0.04; 'encoding': 0.05; 'error:': 0.07; "subject:' ": 0.07; 'username,': 0.07; 'string': 0.09; 'ascii': 0.09; 'encode': 0.09; 'host,': 0.09; 'idea?': 0.09; 'line:': 0.09; 'subject:position': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'windows': 0.15; 'bit.': 0.16; 'cc:name:python list': 0.16; 'codec': 0.16; 'debugged': 0.16; 'eclipse': 0.16; 'fabio': 0.16; 'non-ascii': 0.16; 'ordinal': 0.16; 'reproduce': 0.16; 'subject: \n ': 0.16; 'timeout': 0.16; 'timeout)': 0.16; '\xc2\xa0i': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'properly': 0.19; 'select': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'unicode': 0.24; 'mon,': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'options': 0.25; '>': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'file:': 0.31; 'os,': 0.31; 'username': 0.31; 'skip:c 30': 0.32; 'run': 0.32; 'url:python': 0.33; 'guess': 0.33; 'problem': 0.35; "can't": 0.35; 'common': 0.35; 'connection': 0.35; 'skip:u 20': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'nov': 0.38; 'skip:[ 10': 0.38; 'skip:& 20': 0.39; 'subject:can': 0.39; 'url:mail': 0.40; 'skip:u 10': 0.60; 'skip:\xc2 10': 0.60; 'skip:* 10': 0.61; "you're": 0.61; 'different': 0.65; 'skip:\xe2 10': 0.65; 'here': 0.66; 'internet': 0.71; '8bit%:100': 0.72; 'export': 0.74; 'behavior': 0.77; '8bit%:16': 0.84; '8bit%:70': 0.91; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=HQpPipBbhcf/S7Jh+AWdf+cnEpTq4p60jgfAUDC38KE=; b=fUEBtRuy1ORrA4hfHQc16ycBc+ozOhOYH51sFOMlDo+je1rTnd0otJD/e4J8FZn1IT XJMXng88NZF/7HWg2JHgxLfknMjaadJZmVJaUzIFyH3ck87citWe+8X4zGqHV0B2pH// vIoMRLW7CwRiGL7UYR9VWLX7vcEz8Ic7LTwf0/ZDh4a9DBKxenr/eiAmuE3s5T7dW6Y+ fvAEc1yWzVFX8ID8wH0+z8XTcZuMZbwJs6/+laBJFOlPaoR82EmAsRT+rXrb0pPMZJo/ +HTyHlS7yBpVQRaEdC072xpxxo0uT1PVImzurBjg1so5vPvtac4BQAYH+nFl6k040ZWG G1zw== |
| X-Received | by 10.220.58.1 with SMTP id e1mr15326162vch.0.1384775157758; Mon, 18 Nov 2013 03:45:57 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <002501cee41a$6d8ccdf0$48a669d0$@viettel.com.vn> |
| References | <002501cee41a$6d8ccdf0$48a669d0$@viettel.com.vn> |
| From | Fabio Zadrozny <fabiofz@gmail.com> |
| Date | Mon, 18 Nov 2013 09:45:37 -0200 |
| Subject | Re: UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: ordinal not in range(128) |
| To | Hoàng Tuấn Việt <vietht2@viettel.com.vn> |
| Content-Type | multipart/alternative; boundary=001a11c2c7da5f750e04eb721773 |
| Cc | python list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2836.1384775167.18130.python-list@python.org> (permalink) |
| Lines | 325 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1384775167 news.xs4all.nl 15956 [2001:888:2000:d::a6]:54312 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:59854 |
Show key headers only | View raw
[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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
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
csiph-web