bana
bana

Reputation: 397

Errors when connecting to router with python code

I am trying to connect to some router using the above code and I am using juniperj2320.py module and in test file I have am using code base from this http://subversion.assembla.com/svn/clauzsistel08/trunk/dist/

#!/usr/bin/python
 from localconf import *
 from juniperj2320 import *
 import sys
 import traceback

 SERIALDEVICE = '/dev/ttyUSB0'

 # Now configure the router
 try:
    router = JuniperJ2320(SERIALDEVICE)

 except RouterConfigurationException, err:
    print "Router configuration error: ", err
    print "Please try again."
    sys.exit(1)

but am getting this following error


    ./test.py
    > /root/pyserial-2.6/examples/serialrouter.py(37)__init__()
    -> serial.Serial.__init__(self, serialdevice, baudrate=baudrate, \
    (Pdb) c
    Traceback (most recent call last):
      File "./test.py", line 30, in 
        router = JuniperJ2320(SERIALDEVICE)
      File "/root/pyserial-2.6/examples/juniperj2320.py", line 32, in __init__
        BYTESIZE, PARITY, STOPBITS, TIMEOUT)
      File "/root/pyserial-2.6/examples/serialrouter.py", line 44, in __init__
        fdpexpect.fdspawn.__init__(self, self.fileno())
      File "/usr/lib/python2.6/site-packages/fdpexpect.py", line 40, in __init__
        spawn.__init__(self, None, args, timeout, maxread, searchwindowsize, logfile                                                                                        )
      File "/usr/lib/python2.6/site-packages/pexpect.py", line 412, in __init__
        self.closed = True # File-like object.
    AttributeError: can't set attribute

and absolutely clue less on wat happening here ! any help ll be greatly appreciated

thanks

Upvotes: 0

Views: 511

Answers (2)

Lars Nordin
Lars Nordin

Reputation: 2828

Instead of writing your own serial communications program wouldn't be easier to have pexpect drive a serial program like minicom?

Upvotes: 0

neirbowj
neirbowj

Reputation: 645

This is a little bit of a shot in the dark, because I'm not familiar with the modules you're using, but based on the traceback, it looks like the constructor is expecting a file-like object, not just a file path. Try this instead.

SERIALDEVICE = '/dev/ttyUSB0'

# Now configure the router
try:
    router = JuniperJ2320(open(SERIALDEVICE))

Upvotes: 0

Related Questions