M-o-a-T / asyncari

Asterisk Resource Interface for Trio
Other
23 stars 17 forks source link

Q: resources.json not found #2

Open tkang007 opened 1 year ago

tkang007 commented 1 year ago

Hi there,

First of all, I would like to appreciate for your contributions.
I am evaluating asyncari package to integrate with services, such as Google dialogflow, stt and tts.

After finish basic Asterisk functionality with dialplan, also evaluated some basic examples with others(nodejs and golang). asyncari looks like perfectly fit in my case, but hit a case as below, it looks like configuration or version issue.

Could you please any hits for this case?
Thanks in advance!!!

Environment:

   Asterisk 18.9.0, Python 3.11, asyncari 0.18.8,  CenotOS 8 Stream.

Error:

asks.errors.BadStatus: 404 Client Error: Not Found for url: http://localhost:8088/ari/api-docs/resources.json?api_key=asterisk%3Aasterisk
Run with example
============
(venv) [vagrant@c8a1 basic]$ python example.py
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:asyncswagger11.client:Loading from http://localhost:8088/ari/api-docs/resources.json
Traceback (most recent call last):
  File "/projects/hello-ari/clone-python-ari/asyncari/examples/basic/example.py", line 90, in <module>
    anyio.run(main)
  File "/home/vagrant/venv/lib64/python3.11/site-packages/anyio/_core/_eventloop.py", line 70, in run
    return asynclib.run(func, *args, **backend_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vagrant/venv/lib64/python3.11/site-packages/anyio/_backends/_asyncio.py", line 292, in run
    return native_run(wrapper(), debug=debug)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/vagrant/venv/lib64/python3.11/site-packages/anyio/_backends/_asyncio.py", line 287, in wrapper
    return await func(*args)
           ^^^^^^^^^^^^^^^^^
  File "/projects/hello-ari/clone-python-ari/asyncari/examples/basic/example.py", line 81, in main
    async with asyncari.connect(ast_url, ast_app, ast_username,ast_password) as client:
  File "/home/vagrant/venv/lib64/python3.11/site-packages/async_generator/_util.py", line 34, in __aenter__
    return await self._agen.asend(None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vagrant/venv/lib64/python3.11/site-packages/asyncari/__init__.py", line 36, in connect
    async with client:
  File "/home/vagrant/venv/lib64/python3.11/site-packages/asyncari/client.py", line 111, in __aenter__
    await self._init()
  File "/home/vagrant/venv/lib64/python3.11/site-packages/asyncari/client.py", line 262, in _init
    await self.swagger.init()
  File "/home/vagrant/venv/lib64/python3.11/site-packages/asyncswagger11/client.py", line 205, in init
    self.api_docs = await self.loader.load_resource_listing(self.url)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vagrant/venv/lib64/python3.11/site-packages/asyncswagger11/swagger_model.py", line 158, in load_resource_listing
    resource_listing = await json_load_url(self.http_client, resources_url)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vagrant/venv/lib64/python3.11/site-packages/asyncswagger11/swagger_model.py", line 121, in json_load_url
    resp = await http_client.request('GET', url)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vagrant/venv/lib64/python3.11/site-packages/asyncswagger11/http_client.py", line 215, in request
    response.raise_for_status()
  File "/home/vagrant/venv/lib64/python3.11/site-packages/asks/response_objects.py", line 47, in raise_for_status
    raise BadStatus(
asks.errors.BadStatus: 404 Client Error: Not Found for url: http://localhost:8088/ari/api-docs/resources.json?api_key=asterisk%3Aasterisk
(venv) [vagrant@c8a1 basic]$

CLI for http status 
====
c8a1*CLI> http show status
HTTP Server Status:
Prefix:
Server: Asterisk/18.9.0
Server Enabled and Bound to 0.0.0.0:8088

HTTPS Server Enabled and Bound to 0.0.0.0:8089

Enabled URI's:
/httpstatus => Asterisk HTTP General Status
/phoneprov/... => Asterisk HTTP Phone Provisioning Tool
/metrics/... => Prometheus Metrics URI
/static/... => Asterisk HTTP Static Delivery
/ws => Asterisk HTTP WebSocket

Enabled Redirects:
  None.
[2023-04-27 10:23:16.256] WARNING[7295]: res_pjsip_pubsub.c:3353 pubsub_on_rx_publish_request: No registered publish handler for event presence from 100
c8a1*CLI>

cURL
====
(venv) [vagrant@c8a1 basic]$ curl http://localhost:8088/ari/api-docs/resources.json
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr />
<address>Asterisk/18.9.0</address>
</body></html>
(venv) [vagrant@c8a1 basic]$

(venv) [vagrant@c8a1 basic]$ curl http://localhost:8088/httpstatus

Asterisk HTTP Status

  Asterisk™ HTTP Status

ServerAsterisk/18.9.0
Prefix
Bind Address0.0.0.0
Bind Port8088
SSL Bind Port8089


Asterisk and Digium are registered trademarks of Digium, Inc.
muslih-DIY commented 1 year ago

Please refer the asterisk documentation for configuring ari . you are not enabled the ari in asterisk configuration.

ari.conf

 [general]
 enabled = yes 
 pretty = yes 

[asterisk]
type = user
read_only = no
password = asterisk