Skip to content

Commit

Permalink
Merge pull request #156 from LibertyGlobal/master
Browse files Browse the repository at this point in the history
ignore non-UTF-8 input
  • Loading branch information
ktbyers committed Jan 18, 2016
2 parents 4d81783 + fd844a7 commit 7c2b3fd
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion netmiko/avaya/avaya_ers_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def special_login_handler(self, delay_factor=.5):
i = 0
while i <= 12:
if self.remote_conn.recv_ready():
output = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
output = self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
if 'Ctrl-Y' in output:
self.remote_conn.sendall(CTRL_Y)
if 'sername' in output:
Expand Down
16 changes: 8 additions & 8 deletions netmiko/base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ def establish_connection(self, sleep_time=3, verbose=True, timeout=8,
time.sleep(sleep_time)
# Strip any initial data
if self.remote_conn.recv_ready():
return self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
return self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
else:
i = 0
while i <= 10:
# Send a newline if no data is present
self.remote_conn.sendall('\n')
time.sleep(.5)
if self.remote_conn.recv_ready():
return self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
return self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
else:
i += 1
return ""
Expand Down Expand Up @@ -216,7 +216,7 @@ def disable_paging(self, command="terminal length 0\n", delay_factor=.5):
time.sleep(1 * delay_factor)

# Clear the buffer on the screen
output = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
output = self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
if self.ansi_escape_codes:
output = self.strip_ansi_escape_codes(output)

Expand Down Expand Up @@ -259,7 +259,7 @@ def set_base_prompt(self, pri_prompt_terminator='#',
self.clear_buffer()
self.remote_conn.sendall("\n")
self.wait_for_recv_ready(delay_factor)
prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')

# Some platforms have ANSI escape codes
if self.ansi_escape_codes:
Expand Down Expand Up @@ -302,7 +302,7 @@ def find_prompt(self, delay_factor=.5):
self.remote_conn.sendall("\n")
time.sleep(1 * delay_factor)

prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')

# Some platforms have ANSI escape codes
if self.ansi_escape_codes:
Expand All @@ -326,7 +326,7 @@ def clear_buffer(self):
'''

if self.remote_conn.recv_ready():
return self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
return self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
else:
return None

Expand Down Expand Up @@ -369,7 +369,7 @@ def send_command(self, command_string, delay_factor=.5, max_loops=30,
i += 1
# Keep reading data as long as available (up to max_loops)
if self.remote_conn.recv_ready():
output += self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
output += self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
else:
not_done = False

Expand Down Expand Up @@ -447,7 +447,7 @@ def send_command_expect(self, command_string, expect_string=None,
if self.remote_conn.recv_ready():
if debug:
print("recv_ready = True")
output += self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
output += self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
if search_pattern in output:
break
else:
Expand Down
4 changes: 2 additions & 2 deletions netmiko/cisco/cisco_asa_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def enable(self, delay_factor=.5):
self.remote_conn.sendall("\nenable\n")
time.sleep(1 * delay_factor)

output = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
output = self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
if 'password' in output.lower():
self.remote_conn.sendall(self.secret + '\n')
self.remote_conn.sendall('\n')
time.sleep(1 * delay_factor)
output += self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
output += self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')

if not self.check_enable_mode():
raise ValueError("Failed to enter enable mode")
Expand Down
5 changes: 2 additions & 3 deletions netmiko/cisco/cisco_wlc_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def special_login_handler(self, delay_factor=.5):
i = 0
while i <= 12:
if self.remote_conn.recv_ready():
output = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
output = self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
if 'login as' in output or 'User' in output:
self.remote_conn.sendall(self.username + '\n')
elif 'Password' in output:
Expand Down Expand Up @@ -84,8 +84,7 @@ def send_command_w_enter(self, *args, **kwargs):
i += 1
if self.remote_conn.recv_ready():
# Unicode error occurred in output (errors=ignore strips this out).
output += self.remote_conn.recv(MAX_BUFFER).decode('utf-8',
errors='ignore')
output += self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
else:
not_done = False

Expand Down
2 changes: 1 addition & 1 deletion netmiko/fortinet/fortinet_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def establish_connection(self, sleep_time=3, verbose=True, timeout=8, use_keys=F

# Strip the initial router prompt
time.sleep(sleep_time)
return self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
return self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')

def config_mode(self, config_command=''):
'''
Expand Down
2 changes: 1 addition & 1 deletion netmiko/hp/hp_comware_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator=']',
self.remote_conn.sendall("\n")
time.sleep(1 * delay_factor)

prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
prompt = self.normalize_linefeeds(prompt)

# If multiple lines in the output take the last line
Expand Down
2 changes: 1 addition & 1 deletion netmiko/huawei/huawei_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator=']',
self.remote_conn.sendall("\n")
time.sleep(1 * delay_factor)

prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
prompt = self.normalize_linefeeds(prompt)

# If multiple lines in the output take the last line
Expand Down
2 changes: 1 addition & 1 deletion netmiko/juniper/juniper_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def enter_cli_mode(self):
while True:
self.remote_conn.sendall("\n")
time.sleep(1)
cur_prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
cur_prompt = self.remote_conn.recv(MAX_BUFFER).decode('utf-8', 'ignore')
if re.search(r'root@.*%', cur_prompt):
self.remote_conn.sendall("cli\n")
time.sleep(1)
Expand Down

0 comments on commit 7c2b3fd

Please sign in to comment.