Access VICIdial API via Python

All installation and configuration problems and questions

Moderators: gerski, enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, Michael_N

Access VICIdial API via Python

Postby ABretten » Mon Jul 19, 2021 9:08 am

Hey,

Im trying to access the API just using the basic tokens available in the docs here : http://www.vicidial.org/docs/NON-AGENT_API.txt



Im using python 3.8.8 and using this code :


import requests
from requests.auth import HTTPBasicAuth

url = 'http://server/vicidial/non_agent_api.php'
auth =('6666','1234')

requests.get(url,auth=auth)


Im getting the following error :
NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001CC9B5A7FA0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

Would anyone be able to tell me where im going wrong?

Thanks
Alex
ABretten
 
Posts: 2
Joined: Sat Jul 17, 2021 9:09 am

Re: Access VICIdial API via Python

Postby carpenox » Mon Jul 19, 2021 1:34 pm

not sure if this will help since this is a php derivative but it may get you on the right track: https://github.com/masterfermin02/vicid ... Client.php
Alma Linux 9.4 | SVN Version: 3890 | DB Schema Version: 1721 | Asterisk 18.21.1 | PHP8
www.dialer.one -:- 1-833-DIALER-1 -:- https://linktr.ee/CyburDial -:- WA: +19549477572
GC: https://join.skype.com/ujkQ7i5lV78O | DC: https://discord.gg/DVktk6smbh
carpenox
 
Posts: 2428
Joined: Wed Apr 08, 2020 2:02 am
Location: St Petersburg, FL

Re: Access VICIdial API via Python

Postby mjohn425 » Tue Jul 20, 2021 7:58 am

Hi Alex,

The API that you are trying to use doesn't use Basic auth (i.e auth through the Authorization header) so you won't be able to pass it this way. The API expects the user and password as part of the query string and sometimes a target user depending on the function. In saying that, the getaddrinfo failed is a DNS lookup issue so probably check the value in the url column and check that it's actually pointing to the server. Note: you can test all of them in your browser address bar before moving into python.

Cheers.
OS: VICIBox 9.0.1 OpenSuse 15.1 | VERSION: 2.14-742a BUILD: 200327-1715 | Asterisk: 13.21.1-vici | SVN: 3205 DB Schema: 1588
Linux: 4.12.14-lp151.28.44-default | MYSQL: Ver 15.1 Distrib 10.2.31-MariaDB | Perl: v5.26.1 | php: v7.2.5
mjohn425
 
Posts: 51
Joined: Tue Jan 21, 2020 1:20 am

Re: Access VICIdial API via Python

Postby ABretten » Tue Jul 20, 2021 8:22 am

carpenox wrote:not sure if this will help since this is a php derivative but it may get you on the right track: https://github.com/masterfermin02/vicid ... Client.php

Thanks! Checked it out and its helped me understand the API functions.

mjohn425 wrote:Hi Alex,

The API that you are trying to use doesn't use Basic auth (i.e auth through the Authorization header) so you won't be able to pass it this way. The API expects the user and password as part of the query string and sometimes a target user depending on the function. In saying that, the getaddrinfo failed is a DNS lookup issue so probably check the value in the url column and check that it's actually pointing to the server. Note: you can test all of them in your browser address bar before moving into python.

Cheers.


So when it says "server" in the URL, am I meant to be quoting an IP address of the server my company uses? - Iv seen in the non agent docs the following is listed as a sample string : "http://server/vicidial/non_agent_api.php?function=version"

When i try pasting that in my address bar it doesnt return anything!
ABretten
 
Posts: 2
Joined: Sat Jul 17, 2021 9:09 am

Re: Access VICIdial API via Python

Postby mjohn425 » Tue Jul 20, 2021 9:35 am

Yep most definitely replacing server with the ip address or if they have a fully qualified domain name chuck that in there instead.
OS: VICIBox 9.0.1 OpenSuse 15.1 | VERSION: 2.14-742a BUILD: 200327-1715 | Asterisk: 13.21.1-vici | SVN: 3205 DB Schema: 1588
Linux: 4.12.14-lp151.28.44-default | MYSQL: Ver 15.1 Distrib 10.2.31-MariaDB | Perl: v5.26.1 | php: v7.2.5
mjohn425
 
Posts: 51
Joined: Tue Jan 21, 2020 1:20 am


Return to Support

Who is online

Users browsing this forum: No registered users and 114 guests