user167707
user167707

Reputation: 1

str object not callable on a script

I'm running a script on a network switch:

import exsh

def main():

        #result='0'
        #print result
        result=exsh.clicmd('show ver', capture=True)
        print result
        result=exsh.clicmd('sh switch', capture=True)
        print result
        result=exsh.clicmd('sh vlan', capture=True)
        print result
        exsh.clicmd('create vlan vlan10 tag 10')
        result=exsh.clicmd('sh vlan10', capture=True)
        print result
        exsh.clicmd=('del vlan10')
        result=exsh.clicmd('sh vlan', capture=True)
        print result

if True: main()

When I run it, I get the expected output until it gets to line 18:

Traceback (most recent call last):
  File "/config/test.py", line 23, in <module>
    if True: main()
  File "/config/test.py", line 18, in main
    result=exsh.clicmd('sh vlan', capture=True)
TypeError: 'str' object is not callable

What becomes even more unexpected is if I run it again immediately afterwards the error now occurs at line 8:

* X460-24p.2 # run script test.py
Traceback (most recent call last):
  File "/config/test.py", line 23, in <module>
    if True: main()
  File "/config/test.py", line 8, in main
    result=exsh.clicmd('show ver', capture=True)
TypeError: 'str' object is not callable

Not sure how to trace the problem.

Upvotes: 0

Views: 105

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180391

You set exsh.clicmd=('del vlan10') which makes exsh.clicmda string then you try to call it after with result=exsh.clicmd('sh vlan', capture=True):

In [1]: foo = ('del vlan10')

In [2]: type(foo)
Out[2]: str

In [3]: foo()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-624891b0d01a> in <module>()
----> 1 foo()

TypeError: 'str' object is not callable

Upvotes: 2

Related Questions