cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2106
Views
0
Helpful
1
Replies

Cisco ISE, Python and PHP

dasampson
Level 1
Level 1

Hey Everyone,

I wrote a Python Class for ISE to find/add/remove devices.  It works great when I call it from another python program.  To help my Network Engineers, I want to embed this into a php page/form which will get information like Hostname and IP address so that I can create the device in ISE.  This is just a simple start of more to come.

However, I am running into issues when I try to call my python application from an PHP page run on Apache.  The issue I run into is with the requests module.  My python script, quits running when it gets to the get command.  Any help that anyone could provide would be greatly appreciated.  I am banging my head on the wall trying to figure out what is wrong.

I have simplified my python script in order to figure what what is going wrong.  If someone has a better recommendation on how to call Python scripts from the web, I am open to suggestions.

The python script doesn't expect anything when it is called, I just removed the user and password from the script.

Here is what is returned when I run it from a command line:

$ python test.py

(u'172.18.251.225', u'25502760-d9a5-11e6-80af-00505684337f', u'MNIT LAN Device')

$

Here is my python script:

#!/usr/bin python

import json

import requests

ERSUser = 'user'

ERSPassword = 'pass'

s = requests.session()

s.auth = (ERSUser, ERSPassword)

s.verify = True

s.headers.update({

            'Accept': 'application/json',

            'Connection': 'keep_alive',

            'Content_type': 'application/json'

            })

url = "https://www.myserver.com:9060/ers/config/networkdevicefilter=ipaddress.EQ.172.18.251.225"

r = s.get(url)

for i in r.json()['SearchResult']['resources']:

       print (i['name'], i['id'], i['description'])

Here is the part of the php where I call the test.py script:

$command = escapeshellcmd('/usr/bin/python /var/www/cgi-bin/test.py');

$output = shell_exec($command);

echo $output;

Here is from my Apache log:

error: cannot open Packages index using db5 - Permission denied (13)

error: cannot open Packages database in /var/lib/rpm

Traceback (most recent call last):

  File "/var/www/cgi-bin/test.py", line 19, in <module>

    r = s.get(url)

  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 476, in get

    return self.request('GET', url, **kwargs)

  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 464, in request

    resp = self.send(prep, **send_kwargs)

  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 576, in send

    r = adapter.send(request, **kwargs)

  File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 415, in send

    raise ConnectionError(err, request=request)

requests.exceptions.ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))

[dsampson@mnet-ws-dave httpd]$

1 Reply 1

Daniel Finein
Level 1
Level 1

Just reread and it looks like a possible issue with your permissions on the python modules you are calling.  If you didn't install them for everyone, it could be causing you issues.  Go look at what user is calling python (I suspect www-data or httpd) and make sure they are listed as being able to read the libraries.