McJim
McJim

Reputation: 49

python error - attributeError: 'str' object has no attribute

I'm getting the error below when trying to run some python code.

traceback (most recent call last):
File "autovlan4.py", line 48, in <module>
switch.runCmds(1, ["enable", "configure terminal", "vlan " + vlan, "interface " + iface,   "switchport mode access", "switchport access vlan " + vlan, "end" ])
AttributeError: 'str' object has no attribute 'runCmds'

My code is:

import re
from jsonrpclib import Server

def get_vlan_iface_switch():
while True:
    switch_to_change = raw_input("Enter the name of the switch you want to change ")
    vlan = raw_input ("what VLAN ID do you want to add? (e.g. 100) ")
    iface = raw_input("what interface do you want to add the VLAN to? (e.g. eth10) ")
    switch  = Server("https://lab:lab@" + switch_to_change + "/command-api")
    print "So, we are adding VLAN %r to interface %r on %r" % (vlan, iface,    switch_to_change)

    if raw_input("Are the details above correct? (Yes/No) ")[0].lower() == "y":
         return vlan,iface,switch_to_change
    print "Please Fix Your Entries!"


# Runs commands to add gathered config to switch

vlan,iface,switch = get_vlan_iface_switch()

print ("Making the changes...")
switch.runCmds(1, ["enable", "configure terminal", "vlan " + vlan, "interface " + iface,  "switchport mode access", "switchport access vlan " + vlan, "end" ])

print ("Change completed")

I'm kinda lost, very new to python. Any help would be greatly appreciated.

Upvotes: 0

Views: 2236

Answers (1)

Hugh Bothwell
Hugh Bothwell

Reputation: 56624

It looks like get_vlan_iface_switch() should return vlan,iface,switch in line 13. Right now, it is returning switch_to_change, which is a string, which has no .runCmds method.

Upvotes: 2

Related Questions