asterisk / ari-py

Library for accessing the Asterisk REST Interface
Other
146 stars 106 forks source link

[Events] Failed to generate an user event #10

Open claudiuolteanu opened 9 years ago

claudiuolteanu commented 9 years ago

Hello folks,

When I generate an user event I receive the following error: "AttributeError: 'dict' object has no attribute 'paramType'" , raised on swaggerpy/client.py line 73. (more details here [1]).

I believe that this is a swagger-py limitation since the parameter type is expected to be 'path' or 'query' and when you generate an user event the type of 'variables' parameter will be 'body' .

Below you can find the code which generates the error:

connection = ari.connect('http://localhost:8088', 'user', 'password') # connect to the ARI server
connection.events.userEvent(eventName="NewEvent", 
                            application='Test', 
                            variables={"variables" : {"var1":"value1"}}) # generate the user event

[1] error

All the best, Claudiu

matt-jordan commented 9 years ago

You're correct. Right now, swagger-py does not support body parameters - as such, it doesn't have support for a dictionary of values that should be converted to JSON.

matt-jordan commented 9 years ago

And, this is a problem in swagger-py, not ari-py (it just happens to break ari-py as well).

litnimax commented 9 years ago

Is swagger-py expected to support body params? Who is responsible for developing it? Thanks.

matt-jordan commented 9 years ago

No one is "responsible". It's an open source project, currently under the Digium repo (since that's what we had available at the time).

https://github.com/digium/swagger-py

Anyone can make a pull request to it.

nhorelik commented 9 years ago

Note that if you really need this functionality, you can still simply make posts manually. For example:

import json
import requests
data = json.dumps({'variables': {'myvar': 'myval'}})
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
auth = ('username', 'password')
params = {'eventName': 'myevent', 'application': 'myappname'}
requests.post('http://127.0.0.1:8088/ari/events/user/myevent',data=data, headers=headers, auth=auth, params=params)

I'd prefer to use ari-py everywhere though, so hopefully this functionality will be added in the next release! See digium/swagger-py#9.