Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using GET() parameters in a python script

Status
Not open for further replies.

deeciple

Technical User
Mar 1, 2012
70
0
0
US
Hi All,

I am trying to send some values to a python script using an AJAX call. The AJAX is calling the script properly because if I plug the values directly into the script it executes properly.

The problem I am having is when I try to send the values to my script by embedding them in the URL. Here is the JavaScript where I am sending the parameters:

JavaScript:
function sndCmd(devID, cmd){
//	alert(devID);
//	alert(cmd);
  var command = new XMLHttpRequest();
   command.onreadystatechange = function() {
    if (command.readyState == 4 && command.status == 200) {
     var result = command.responseText;
    }
  };
  command.open("GET", "[URL unfurl="true"]http://localhost/cgi-bin/kipro/transport.py?devID="+devID+"&cmd="+cmd,[/URL] true);
  command.send();
}

and here is the function I am trying to parse the url with:

Python:
#!C:\Python27\python.exe -u
import cgi
import kipro

data = cgi.fieldStorage()

devID = data.getvalue('devID')
cmd = data.getvalue('cmd')

client = kipro.Client(devID)
client.cmd()

I have researched and the best I could find was the python get() method but every example was using a URL that was included and parsed in the same python script. I don't know how I would use the get() method with a URL that was being sent to the script.

Any help is appreciated.

Thanks in advance,

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top