1

I want to send some parameters from a python script on my server to a php script on my server using HTTP. Suggestions?

2
  • urlopen/urlopen2 can build send GET and POST queries, but you need to elaborate what you want to do Commented Oct 8, 2010 at 6:59
  • Okay: I want to make a GET query from a python script to a php script being served by apache2. Both scripts reside on the same machine/same ip address. Commented Oct 8, 2010 at 7:53

1 Answer 1

2

This is pretty easy using urllib:

import urllib

myurl = 'http://localhost/script.php?var1=foo&var2=bar'

# GET is the default action
response = urllib.urlopen(myurl)  

# Output from the GET assuming response code was 200
data = response.read()            
Sign up to request clarification or add additional context in comments.

2 Comments

Cheers! Given that the same thing could, in a sense, be achieved using stdin or argument passing, what is the relative overhead?
I have no idea, but since you're using Python you can make the script accept use dynamic variables and don't need to resort to system (cli) calls for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.