Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!easy.in-chemnitz.de!news2.arglkargh.de!news.n-ix.net!news.bawue.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'else:': 0.03; 'skip:[ 20': 0.04; 'elif': 0.05; "subject:' ": 0.07; 'username,': 0.07; '22,': 0.09; '8bit%:30': 0.09; '8bit%:78': 0.09; 'dst': 0.09; 'host,': 0.09; 'line:': 0.09; 'lines.': 0.09; 'password)': 0.09; 'subject:position': 0.09; 'true)': 0.09; 'python': 0.11; 'def': 0.12; 'windows': 0.15; "'':": 0.16; '-1,': 0.16; '8bit%:32': 0.16; '>to': 0.16; 'codec': 0.16; 'eclipse': 0.16; 'event):': 0.16; 'inputs': 0.16; 'msg):': 0.16; "new',": 0.16; 'ordinal': 0.16; 'skip:[ 40': 0.16; 'src': 0.16; 'stderr': 0.16; 'str)': 0.16; 'str):': 0.16; 'subject: \n ': 0.16; 'tab': 0.16; 'timeout': 0.16; 'timeout)': 0.16; 'app': 0.19; "skip:' 30": 0.19; 'skip:p 40': 0.19; 'input': 0.22; 'select': 0.22; 'import': 0.22; 'python?': 0.22; 'error': 0.23; 'byte': 0.24; 'skip:c 70': 0.24; 'skip:{ 20': 0.24; 'sorry,': 0.24; 'options': 0.25; 'post': 0.26; 'function': 0.29; 'host': 0.29; 'skip:p 30': 0.29; "skip:' 10": 0.31; 'os,': 0.31; "skip:' 40": 0.31; 'username': 0.31; 'file': 0.32; 'class': 0.32; 'skip:c 30': 0.32; 'run': 0.32; 'text': 0.33; 'plain': 0.33; 'skip:t 40': 0.33; 'style': 0.33; 'skip:_ 10': 0.34; "can't": 0.35; 'connection': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'url:rec-html40': 0.35; 'version': 0.36; 'skip:s 60': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'url:microsoft': 0.37; 'list': 0.37; 'skip:& 10': 0.38; '8bit%:86': 0.38; 'window': 0.38; 'url:office': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'url:schemas': 0.38; 'url:omml': 0.39; 'url:2004': 0.39; 'skip:& 20': 0.39; 'subject:can': 0.39; 'url:12': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; '8bit%:47': 0.60; 'blank': 0.60; 'skip:\xc2 10': 0.60; 'skip:t 30': 0.61; 'from:charset:utf-8': 0.61; 'show': 0.63; 'management': 0.65; 'skip:\xe2 10': 0.65; 'bottom': 0.67; 'close': 0.67; '8bit%:31': 0.68; '8bit%:40': 0.68; '8bit%:50': 0.68; '8bit%:74': 0.68; 'panel': 0.68; 'skip:w 40': 0.68; 'skip:w 30': 0.69; '8bit%:96': 0.70; '8bit%:100': 0.72; '8bit%:94': 0.72; '8bit%:27': 0.74; 'export': 0.74; 'received:203': 0.74; '8bit%:46': 0.78; '8bit%:98': 0.78; '8bit%:16': 0.84; '8bit%:49': 0.84; '8bit%:61': 0.84; '8bit%:82': 0.84; 'comment.': 0.84; 'received:220.231': 0.84; '8bit%:33': 0.91; '8bit%:54': 0.91; '8bit%:56': 0.91; '8bit%:58': 0.91; '8bit%:70': 0.91; '8bit%:18': 0.93; '8bit%:55': 0.93; '8bit%:67': 0.93; '8bit%:42': 0.95 Date: Tue, 19 Nov 2013 15:39:56 +0700 From: =?utf-8?B?SG/DoG5nIFR14bqlbiBWaeG7h3Q=?= Subject: RE: UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128) Sender: vietht2@viettel.com.vn To: python-list@python.org MIME-version: 1.0 X-Mailer: Microsoft Outlook 14.0 Content-Type: multipart/alternative; boundary="Boundary_(ID_oK5MBHtGHXoVbM6v7o3uQQ)" Content-language: en-us Thread-index: Ac7lAras9yK9o7aBTk+5gBbCJg/m7g== X-Mailman-Approved-At: Tue, 19 Nov 2013 09:43:04 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 2024 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384850586 news.xs4all.nl 15998 [2001:888:2000:d::a6]:37676 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59964 This is a multipart message in MIME format. --Boundary_(ID_oK5MBHtGHXoVbM6v7o3uQQ) Content-type: text/plain; charset=utf-8 Content-transfer-encoding: quoted-printable Hi Terry, Thanks for your comment. =20 >To better help us help you, what exact version of Python? I use Python 2.7.5 =20 >Please post plain text without html. Sorry, I will do it. =20 >Please post programs single spaced with just occasional blank lines. =20 File my_program.py =20 import wx.aui import paramiko import telnetlib from LinuxHostPage import * from WindowsHostPage import * from AIXHostPage import * Publisher =3D pub.Publisher() TIMEOUT =3D 3 =20 class MainWindow(wx.Frame): def __init__(self, parent, title): =20 self.os =3D '' self.connection =3D [] =20 wx.Frame.__init__(self, parent, title=3Dtitle) self.SetBackgroundColour('LightGray') =20 # A Statusbar in the bottom of the window self.CreateStatusBar()=20 self.SetStatusText("Please input credentials.") =20 # Publisher Publisher().subscribe(self.change_statusbar, 'change_statusbar') =20 # Input box self.input_panel =3D wx.Panel(self) self.host =3D wx.StaticText(self.input_panel, -1, 'Host') self.host_entry =3D wx.TextCtrl(self.input_panel) self.username =3D wx.StaticText(self.input_panel, -1, = 'Username') self.username_entry =3D wx.TextCtrl(self.input_panel) self.password =3D wx.StaticText(self.input_panel, -1, = 'Password') self.password_entry =3D wx.TextCtrl(self.input_panel, style =3D = wx.TE_PASSWORD) self.connect_btn =3D wx.Button(self.input_panel, -1, 'Connect') ## List box self.os_text =3D wx.StaticText(self.input_panel, -1, 'OS') self.choice_list =3D wx.Choice(self.input_panel, = choices=3D['Redhat', 'SuSE', 'Windows', 'Solaris', 'AIX']) self.choice_list.SetSelection(2) =20 self.input_sizer =3D wx.BoxSizer(wx.HORIZONTAL) self.input_sizer.Add((7,0)) self.input_sizer.Add(self.os_text, flag =3D wx.ALIGN_CENTER) self.input_sizer.Add((7,0)) self.input_sizer.Add(self.choice_list, flag =3D wx.ALIGN_CENTER) self.input_sizer.Add((7,0)) self.input_sizer.Add(self.host, flag =3D wx.ALIGN_CENTER) self.input_sizer.Add((7,0)) self.input_sizer.Add(self.host_entry, flag =3D wx.ALIGN_CENTER) self.input_sizer.Add((7,0)) self.input_sizer.Add(self.username, flag =3D wx.ALIGN_CENTER) self.input_sizer.Add((7,0)) self.input_sizer.Add(self.username_entry, flag =3D = wx.ALIGN_CENTER) self.input_sizer.Add((7,0)) self.input_sizer.Add(self.password, flag =3D wx.ALIGN_CENTER) self.input_sizer.Add((7,0)) self.input_sizer.Add(self.password_entry, flag =3D = wx.ALIGN_CENTER) self.input_sizer.Add((7,0)) self.input_sizer.Add(self.connect_btn, flag =3D wx.ALIGN_CENTER) =20 self.input_panel.SetSizer(self.input_sizer) =20 # Function panel self.notebook =3D wx.aui.AuiNotebook(self) =20 # Top Sizer self.sizer =3D wx.BoxSizer(wx.VERTICAL) self.sizer.Add((0,7)) self.sizer.Add(self.input_panel, border =3D 10) self.sizer.Add((0,7)) self.sizer.Add(self.notebook, 1, wx.EXPAND) self.sizer.Add((0,7)) =20 self.SetSizerAndFit(self.sizer) =20 # Show Frame self.Show() =20 # Events self.connect_btn.Bind(wx.EVT_BUTTON, self.on_connect) self.Bind(wx.EVT_CLOSE, self.on_close) =20 def change_statusbar(self, msg): self.SetStatusText(msg.data) =20 def ssh(self, host, username, password): connection =3D paramiko.SSHClient() connection.set_missing_host_key_policy(paramiko.AutoAddPolicy()) connection.connect(host, 22, username, password) stdin, stdout, stderr =3D connection.exec_command('ls') stdin.write('expected_input\n') stdin.flush() return connection =20 def telnet(self, host, os, username, password): connection =3D telnetlib.Telnet(host) connection.read_until('login: ') connection.write(username + '\r') connection.read_until('assword: ') connection.write(password + '\r') if os =3D=3D 'windows': connection.read_until('>', timeout =3D TIMEOUT) elif os =3D=3D 'aix': connection.read_until('#', timeout =3D TIMEOUT) return connection =20 def get_os(self): os =3D self.choice_list.GetLabel() return os.lower() =20 def on_connect(self, event): self.os =3D self.get_os() self.connect_btn.Disable() host =3D self.host_entry.GetValue() username =3D self.username_entry.GetValue() password =3D self.password_entry.GetValue() self.SetStatusText('Connecting... Please wait.') self.connect_btn.Disable() =20 if self.os =3D=3D 'redhat' or self.os =3D=3D 'suse': self.connection =3D self.ssh(host, username, password) page =3D LinuxHostPage(self, self.connection, self.os, = Publisher) elif self.os =3D=3D 'windows': self.connection =3D self.telnet(host, self.os, username, = password) page =3D WindowsHostPage(self, self.connection, self.os, = Publisher) elif self.os =3D=3D 'aix': self.connection =3D self.telnet(host, self.os, username, = password) page =3D AIXHostPage(self, self.connection, self.os, = Publisher) =20 self.SetStatusText('Connected') self.connect_btn.Enable() # Connection tab self.notebook.AddPage(page, host, select =3D True) =20 def close_connection(self): self.connection.close()=20 =20 # Clean up and close def on_close(self, event): self.close_connection self.Destroy() =20 def on_gen(self, event): # Validate inputs if self.src_input.GetLabel() =3D=3D '' or = self.protocol_input.GetLabel()=3D=3D'': # Set status bar wx.MessageBox('Please input all required fields!', 'Info', = wx.OK | wx.ICON_INFORMATION) return =20 # Src IP src_ip =3D '-s ' + self.src_input.GetLabel() =20 # Protocol proto =3D '-p ' + self.protocol_input.GetLabel().lower() =20 # Src port src_port =3D self.src_port_input.GetLabel().lower().strip() if src_port =3D=3D '(optional)' or src_port =3D=3D '': src_port =3D '' else: src_port =3D '--sport ' + src_port=20 =20 # Dst port dst_port =3D self.dst_port_input.GetLabel().lower().strip() if dst_port !=3D '': dst_port =3D '--dport ' + dst_port=20 =20 # Target target =3D self.target_input.GetLabel().strip() if target =3D=3D '(optional)' or target =3D=3D '': target =3D '-j ACCEPT' else: target =3D '-j ' + target.upper() =20 # Rule if src_port =3D=3D '': rule =3D '{:10s}{:30s}{:10s}{:20s}{:22s}{:20s}'.format('-A = INPUT', src_ip, proto, dst_port, '-m state --state NEW', target) else: rule =3D = '{:10s}{:30s}{:10s}{:20s}{:20s}{:22s}{:20s}'.format('-A INPUT', src_ip, = proto, src_port, dst_port, '-m state --state NEW', target) =20 self.rule.Clear() self.rule.WriteText(rule) self.rule.Enable() =20 # Set status bar self.set_status_bar('Generated rule successfully.') =20 def set_status_bar(self, str): Publisher().sendMessage(('change_statusbar'), str) =20 app =3D wx.App(False) frame =3D MainWindow(None, "Firewall Management Tool") frame.Maximize() app.MainLoop() =20 =20 I can run the program in Eclipse and telnet successfully to a Windows = host. =20 But when I export to .exe file by py2exe: =20 python gen_exe.py py2exe =20 =20 File gen_exe.py: =20 from distutils.core import setup import py2exe =20 setup( options =3D { "py2exe":{ "packages": ['wx.lib.pubsub'], "dll_excludes": ["MSVCP90.dll", "HID.DLL", "w9xpopen.exe"], } }, console =3D [{'script': =E2=80=98my_program.py'}] ) =20 When I run my_program.exe, this error is displayed: =20 UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: = ordinal not in range(128) =20 at line: =20 connection.write(username + '\r') =20 -- Viet --Boundary_(ID_oK5MBHtGHXoVbM6v7o3uQQ) Content-type: text/html; charset=utf-8 Content-transfer-encoding: quoted-printable

Hi = Terry,

Thanks for your comment.

 

>To better help us help you, what exact version = of Python?

I use Python = 2.7.5

 

>Please post plain text without = html.

Sorry, I will do it.

 

>Please post programs single spaced with just = occasional blank lines.

 

File my_program.py

 

import<= span style=3D'font-size:10.0pt;font-family:Consolas;color:black'> = wx.aui

import<= span style=3D'font-size:10.0pt;font-family:Consolas;color:black'> = paramiko

import<= span style=3D'font-size:10.0pt;font-family:Consolas;color:black'> = telnetlib

from = LinuxHostPage import<= /u> = *

from = WindowsHostPage import<= /u> = *

from = AIXHostPage import<= /u> = *

Publisher = =3D pub.Publisher()

TIMEOUT =3D = 3

 <= /p>

class = MainWindow(wx.Frame):

=C2=A0=C2=A0=C2= =A0 def = __init__(self, parent, title):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0self.os =3D ''

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.connection =3D []

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0wx.Frame.__init__(self, parent, = title=3Dtitle)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.SetBackgroundColour('LightGray'= )

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# A = Statusbar in the bottom of the window

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.CreateStatusBar()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0self.SetStatusText("Pleas= e input credentials.")

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# = Publisher

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = Publisher().subscribe(self.change_statusbar, 'change_sta= tusbar')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# Input = box

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_panel =3D = wx.Panel(self)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.host =3D = wx.StaticText(self.input_panel, -1, = 'Host')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.host_entry =3D = wx.TextCtrl(self.input_panel)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.username =3D = wx.StaticText(self.input_panel, -1, = 'Usernam= e')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.username_entry =3D = wx.TextCtrl(self.input_panel)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.password =3D = wx.StaticText(self.input_panel, -1, = 'Password'<= /span>)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.password_entry =3D = wx.TextCtrl(self.input_panel, style =3D = wx.TE_PASSWORD)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.connect_btn =3D = wx.Button(self.input_panel, -1, = 'Connect')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 ## List = box

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.os_text =3D = wx.StaticText(self.input_panel, -1, = 'OS'= )

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.choice_list =3D = wx.Choice(self.input_panel, choices=3D['Redhat<= /u>', = 'SuSE', = 'Windows', = 'Solaris= ', = 'AIX'])

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.choice_list.SetSelection(2)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0self.input_sizer =3D = wx.BoxSizer(wx.HORIZONTAL)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_sizer.Add((7,0))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.input_sizer.Add(self.os_text, flag =3D = wx.ALIGN_CENTER)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_sizer.Add((7,0))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.input_sizer.Add(self.choice_list, flag =3D = wx.ALIGN_CENTER)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_sizer.Add((7,0))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.input_sizer.Add(self.host, flag =3D = wx.ALIGN_CENTER)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_sizer.Add((7,0))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.input_sizer.Add(self.host_entry, flag =3D = wx.ALIGN_CENTER)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_sizer.Add((7,0))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.input_sizer.Add(self.username, flag =3D = wx.ALIGN_CENTER)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_sizer.Add((7,0))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.input_sizer.Add(self.username_entry, flag =3D = wx.ALIGN_CENTER)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_sizer.Add((7,0))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.input_sizer.Add(self.password, flag =3D = wx.ALIGN_CENTER)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_sizer.Add((7,0))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.input_sizer.Add(self.password_entry, flag =3D = wx.ALIGN_CENTER)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.input_sizer.Add((7,0))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.input_sizer.Add(self.connect_btn, flag =3D = wx.ALIGN_CENTER)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0self.input_panel.SetSizer(self= .input_sizer)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 = =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# Function = panel

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.notebook =3D = wx.aui.AuiNotebook(self)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# Top = Sizer

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.sizer =3D = wx.BoxSizer(wx.VERTICAL)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.sizer.Add((0,7))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.sizer.Add(self.input_panel, border =3D 10)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.sizer.Add((0,7))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.sizer.Add(self.notebook, = 1, = wx.EXPAND)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.sizer.Add((0,7))

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0self.SetSizerAndFit(self.s= izer)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# Show = Frame

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.Show()

 <= /p>

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 # = Events

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.connect_btn.Bind(wx.EVT_BUTTON, = self.on_connect)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.Bind(wx.EVT_CLOSE, = self.on_close)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0def = change_statusbar(self, msg):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.SetStatusText(msg.data)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0def = ssh(self, host, username, password):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 connection =3D = paramiko.SSHClient()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 connection.connect(host, 22, = username, password)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 stdin, stdout, stderr =3D = connection.exec_command('ls'= )

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 stdin.write('expected_i= nput\n')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 stdin.flush()

=C2=A0 = =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return<= span style=3D'font-size:10.0pt;font-family:Consolas;color:black'> = connection

=C2=A0=C2=A0=C2= =A0

=C2=A0=C2=A0=C2= =A0=C2=A0def = telnet(self, host, os, username, password):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 connection =3D = telnetlib.Telnet(host)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 connection.read_until('login: = ')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 connection.write(usernam= e + '\r')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 connection.read_until('assword= : ')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 connection.write(password + '\r'= )

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 if os =3D=3D = 'windows':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = connection.read_until('>', timeout = =3D TIMEOUT)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 elif os = =3D=3D 'aix= ':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = connection.read_until('#'<= /i>, = timeout =3D TIMEOUT)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 return<= span style=3D'font-size:10.0pt;font-family:Consolas;color:black'> = connection

=C2=A0=C2=A0=C2= =A0

=C2=A0=C2=A0=C2= =A0=C2=A0def = get_os(self):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 os =3D = self.choice_list.GetLabel()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 return<= span style=3D'font-size:10.0pt;font-family:Consolas;color:black'> = os.lower()

=C2=A0=C2=A0=C2= =A0

=C2=A0=C2=A0=C2= =A0=C2=A0def = on_connect(self, event):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.os =3D = self.get_os()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.connect_btn.Disable()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 host =3D = self.host_entry.GetValue()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 username =3D = self.username_entry.GetValue()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 password =3D = self.password_entry.GetValue()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.SetStatusText('Connecting= ... Please wait.')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.connect_btn.Disable()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if = self.os =3D=3D 'redhat<= /u>' = or = self.os =3D=3D 'suse':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.connection =3D self.ssh(host, username, = password)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 page =3D = LinuxHostPage(self, self.connection, self.os, = Publisher)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 elif = self.os =3D=3D 'windows':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.connection =3D self.telnet(host, self.os, = username, password)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 page =3D = WindowsHostPage(self, self.connection, self.os, = Publisher)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 elif = self.os =3D=3D 'aix= ':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = self.connection =3D self.telnet(host, self.os, = username, password)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 page =3D = AIXHostPage(self, self.connection, self.os, = Publisher)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0self.SetStatusText('Connected'= )

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.connect_btn.Enable()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 # = Connection tab

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.notebook.AddPage(page, host, = select =3D True)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=

=C2=A0=C2=A0=C2= =A0=C2=A0def = close_connection(self):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.connection.close()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0# Clean up = and close

=C2=A0=C2=A0=C2= =A0 def = on_close(self, event):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.close_connection

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.Destroy()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0def = on_gen(self, event):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 # Validate = inputs

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 if = self.src_input.GetLabel() =3D=3D '' = or = self.protocol_input.GetLabel()=3D=3D'':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # Set = status bar

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = wx.MessageBox('Please = input all required fields!', = 'Info', wx.OK | = wx.ICON_INFORMATION)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return<= span = style=3D'font-size:10.0pt;font-family:Consolas'>

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# = Src IP

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 src_ip =3D '-s = ' + = self.src_input.GetLabel()

 <= /p>

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 # = Protocol

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 proto =3D '-p = ' + = self.protocol_input.GetLabel().lower()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# = Src port

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 src_port =3D = self.src_port_input.GetLabel().lower().strip()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 if=C2=A0 = src_port =3D=3D '(optional)= ' = or src_port = =3D=3D '':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 src_port =3D = ''

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 else:

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 src_port =3D = '--sport = ' + src_port =

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# = Dst port

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 dst_port =3D = self.dst_port_input.GetLabel().lower().strip()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 if=C2=A0 = dst_port !=3D '':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 dst_port =3D = '--dport= ' + dst_port =

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# = Target

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 target =3D = self.target_input.GetLabel().strip()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 if target = =3D=3D '(optional)= ' = or target = =3D=3D '':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 target =3D = '-j = ACCEPT'

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 else:

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 target =3D = '-j = ' + = target.upper()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# = Rule

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 if src_port = =3D=3D '':

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 rule =3D = '{:10s}{:30= s}{:10s}{:20s}{:22s}{:20s}'.format('-A = INPUT', src_ip, = proto, dst_port, '-m state = --state NEW', = target)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 else:

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 rule =3D = '{:10s}{:30= s}{:10s}{:20s}{:20s}{:22s}{:20s}'.format('-A = INPUT', src_ip, = proto, src_port, dst_port, '-m state = --state NEW', = target)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0self.rule.Clear()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.rule.WriteText(rule)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.rule.Enable()

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0# Set = status bar

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 self.set_status_bar('Generated = rule successfully.')

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0

=C2=A0=C2=A0=C2= =A0=C2=A0def = set_status_bar(self, str):

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 Publisher().sendMessage(('change_sta= tusbar'), = str)

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0

app =3D = wx.App(False)

frame =3D = MainWindow(None, = "Fi= rewall Management Tool")

frame.Maximiz= e()

app.MainLoop(= )

 

 

I can run the program = in Eclipse and telnet successfully to a Windows = host.

 

But when I export to = .exe file by py2exe:

 

python = gen_exe.py py2exe

 

 

File = gen_exe.py:

 

from = distutils.core import setup

import = py2exe

 

setup(

=C2=A0=C2=A0=C2= =A0 options =3D {

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = "py2exe":{

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = "packages": ['wx.lib.pubsub'],

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = "dll_excludes": ["MSVCP90.dll", "HID.DLL", = "w9xpopen.exe"],

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 }

=C2=A0=C2=A0=C2= =A0 },

=C2=A0=C2=A0=C2= =A0 console =3D [{'script': = =E2=80=98my_program.py'}]

)

 

When I = run my_program.exe, this error is displayed:

 

UnicodeDecodeE= rror: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in = range(128)

 

at = line:

 

=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 connection.write(username + = '\r')

 

--<= /span>

Viet

= --Boundary_(ID_oK5MBHtGHXoVbM6v7o3uQQ)--