Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asteriks authenticate problem #61

Open
muhammetfaik opened this issue Jun 21, 2021 · 4 comments
Open

asteriks authenticate problem #61

muhammetfaik opened this issue Jun 21, 2021 · 4 comments

Comments

@muhammetfaik
Copy link

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.
@ludovic-gasc
Copy link
Contributor

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

@muhammetfaik
Copy link
Author

which do I write command ?

@muhammetfaik
Copy link
Author

do you give something information ?

@ldo
Copy link

ldo commented Nov 14, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants