pyst2 icon indicating copy to clipboard operation
pyst2 copied to clipboard

asteriks authenticate problem

Open muhammetfaik opened this issue 3 years ago • 4 comments

I run this code

"""
Example to get list of active channels
"""
import asterisk.manager
import sys

manager = asterisk.manager.Manager()

try:
    # connect to the manager
    try:
        manager.connect('localhost')
        manager.login('muhammet', '123456')

        # get a status report
        response = manager.status()
        print(response)
        
        response = manager.command('core show channels concise')
        print(response.data)

        manager.logoff()
    except asterisk.manager.ManagerSocketException as e:
        print ("Error connecting to the manager: %s" % e.strerror)
        sys.exit(1)
    except asterisk.manager.ManagerAuthException as e:
        print ("Error logging in to the manager: %s" % e.strerror)
        sys.exit(1)
    except asterisk.manager.ManagerException as e:
        print ("Error: %s" % e.strerror)
        sys.exit(1)

finally:
    # remember to clean up
    manager.close()


Add this line

[muhammet]
secret = 123456
deny = 0.0.0.0/0.0.0.0
permit = 192.168.0.0/255.255.255.0
read = all
write = all
writetimeout = 5000

in /etc/manager.conf file but I take this error :


Traceback (most recent call last):
  File "asteriksornek.py", line 27, in <module>
    print ("Error logging in to the manager: %s" % e.strerror)
AttributeError: 'ManagerAuthException' object has no attribute 'strerror'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "asteriksornek.py", line 35, in <module>
    manager.close()
  File "/home/mert/.local/lib/python3.8/site-packages/asterisk/manager.py", line 500, in close
    self.logoff()
  File "/home/mert/.local/lib/python3.8/site-packages/asterisk/manager.py", line 541, in logoff
    response = self.send_action(cdict)
  File "/home/mert/.local/lib/python3.8/site-packages/asterisk/manager.py", line 283, in send_action
    self._sock.write(command.encode('utf8','ignore'))
  File "/usr/lib/python3.8/socket.py", line 684, in write
    self._checkClosed()
ValueError: I/O operation on closed file.

muhammetfaik avatar Jun 21 '21 09:06 muhammetfaik

You might check the firewalls on client and host, or at least, check the TCP connexion content on port 5038 with wireshark, tshark or tcpdump

ludovic-gasc avatar Jun 21 '21 09:06 ludovic-gasc

which do I write command ?

muhammetfaik avatar Jun 21 '21 10:06 muhammetfaik

do you give something information ?

muhammetfaik avatar Jun 21 '21 10:06 muhammetfaik

Two things:

  • You are not actually seeing the right error message, because of the attempt to access the nonexistent strerror attribute. Easier to just remove your problematic catch clauses altogether, and let Python’s default exception reporting tell you what is going wrong.
  • Looks like the API does not like the close() method to be called on an already-closed connection. It might simplify things for close() to be a harmless noop in this situation.

ldo avatar Nov 14 '22 00:11 ldo