Python Forum
AttributeError: 'float' object has no attribute 'decode'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'float' object has no attribute 'decode'
#1
Hi there,

telenet to multiple device, taking host details (ip, username and password) from excel file. this excel file contains
ip username password
10.10.10.1 admin 1234

getting below error

Traceback (most recent call last):
File "zyxelmacport.py", line 37, in <module>
column3 = (worksheet.cell(x,2).value).decode('ascii')
AttributeError: 'float' object has no attribute 'decode'



#!/usr/bin/python
import paramiko
import sys
import os
import xlrd
import unidecode
import telnetlib
import time

def telNetConnection(column1,column2,column3):
 host = [ (column1),]
 for host in host:
  print column1
  user  = (column2)
  password = (column3)
  telnet  = telnetlib.Telnet(host)
  telnet.read_until('User name: ', 3)
  telnet.write(user.encode('ascii') + '\r')
  telnet.read_until('Password: ', 3)
  telnet.write(password.encode('ascii') + '\r')
  telnet.write(ena.encode('ascii') + '\r\n')
  telnet.write('statistics mac 1~48' + '\r\n')
  telnet.write('exit' + '\r')
  output=telnet.read_all()
  f = open(macportdetail, 'w')
  f.write(str(output))


os.chdir("/home/scripts")
workbook = xlrd.open_workbook('zyxeldslams.xlsx')
worksheet = workbook.sheet_by_name('Sheet1')


for x in range(1,4):
 column1 = (worksheet.cell(x,0).value).decode('ascii')
 column2 = (worksheet.cell(x,1).value).decode('ascii')
 column3 = (worksheet.cell(x,2).value).decode('ascii')
 telNetConnection(column1,column2,column3)

some changes, telNetConnection function is not taking numeric password like 1234, when i changed, its started working.

#!/usr/bin/python
import paramiko
import sys
import os
import xlrd
import unidecode
import telnetlib
import time

def telNetConnection(column1,column2,column3):
 host = [ (column1),]
 for host in host:
  print column1
  user  = (column2)
  password = (column3)
  telnet  = telnetlib.Telnet(host)
  telnet.read_until('User name: ', 3)
  telnet.write(user.encode('ascii') + '\r')
  telnet.read_until('Password: ', 3)
  telnet.write(password.encode('ascii') + '\r')
  telnet.write('statistics mac 1~48' + '\r\n')
  telnet.write('exit' + '\r')
  output=telnet.read_all()
  f = open(macportdetail, 'w')
  f.write(str(output))


os.chdir("/home/anna/scripts")
workbook = xlrd.open_workbook('zyxeldslams.xlsx')
worksheet = workbook.sheet_by_name('Sheet1')


for x in range(1,4):
 column1 = (worksheet.cell(x,0).value).decode('ascii')
 column2 = (worksheet.cell(x,1).value).decode('ascii')
 column3 = (worksheet.cell(x,2).value).decode('ascii')
 telNetConnection(column1,column2,column3)
Reply
#2
started working... changed
column3 = (worksheet.cell(x,2).value).decode('ascii')
to
column3 = str(worksheet.cell(x,2).value).decode('utf-8')

but now issue is diferrent

some devices are showing big output where i need to send 'n' if i get Press any key to continue, 'e' to exit, 'n' for nopause

how to do that?

#!/usr/bin/python
import paramiko
import sys
import os
import xlrd
import unidecode
import telnetlib
import time

def telNetConnection(column1,column2,column3):
 host = [ (column1),]
 for host in host:
  print 'Processing'+' '+column1
  user  = (column2)
  password = (column3)
  telnet  = telnetlib.Telnet(host)
  telnet.read_until('User name: ', 3)
  telnet.write(user.encode('ascii') + '\r')
  telnet.read_until('Password: ', 3)
  telnet.write(password.encode('ascii') + '\r')
  telnet.read_until('>',3)
  telnet.write('statistics mac 1~48' + '\r\n')
  telnet.read_until('    Press any key to continue')
  telnet.write('n')
  telnet.read_until('>')
  telnet.write('exit' + '\r')
  output=telnet.read_all()
  f = open('macportdetail.txt', 'w')
  f.write(str(output))


os.chdir("/home/anna/scripts")
workbook = xlrd.open_workbook('zyxeldslams.xlsx')
worksheet = workbook.sheet_by_name('Sheet1')


for x in range(1,4):
 column1 = (worksheet.cell(x,0).value).decode('ascii')
 column2 = (worksheet.cell(x,1).value).decode('ascii')
 column3 = str(worksheet.cell(x,2).value).decode('utf-8')
 telNetConnection(column1,column2,column3)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 721 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,533 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,385 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 704 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,668 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 687 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,216 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,303 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  TypeError: 'float' object is not callable #1 isdito2001 1 1,046 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  Decode string ? JohnnyCoffee 1 791 Jan-11-2023, 12:29 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020