[Tutor] Mod-python
Peter Jessop
pjlists at gmail.com
Mon Jun 12 23:09:21 CEST 2006
>
> I have about 17 lines of text (about system information) that I need to pass to
> a remote web server AND I've been asked to send this data via Apache. I have to
> write a python script that will fetch a URL to pass this text. I understand that
> if I want to use the POST method, I would need to have a page with a submit
> button, and this is not the case. I also know that with GET, the length of the
> url is limited. What is the best way to send a long string?
When you say you that you want to send this data via Apache do you
mean that the web server you are sending to is running Apache or that
you are communicating from one server to another?
If you simply want to emulate a a web page with a submit button that
sends a Post you do it with code a bit like the following
import urllib, urllib2
url = "http://www.somesite.com/somefolder/exampl1.cgi"
dict = {}
dict["field1"] = "value1"
dict["field2"] = "value2"
...
dict["fieldn"] = "valuen"
urldata = urllib.urlencode(dict)
req = urllib2.Request(url)
req.add_header('User-agent','Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0')
fd = urllib2.urlopen(req,urldata)
Regards
Peter Jessop
>
> Hope anyone can point me to the right direction..
> Thanks,
> Patricia
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list