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 doLie Ryan– Lie Ryan2010-10-08 06:59:35 +00:00Commented 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.Anonymous– Anonymous2010-10-08 07:53:06 +00:00Commented Oct 8, 2010 at 7:53
Add a comment
|
1 Answer
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()
2 Comments
mkrecny
Cheers! Given that the same thing could, in a sense, be achieved using stdin or argument passing, what is the relative overhead?
jathanism
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.