pyst2
pyst2 copied to clipboard
asteriks authenticate problem
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.
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
which do I write command ?
do you give something information ?
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 problematiccatch
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 forclose()
to be a harmless noop in this situation.