urllib2 and POST
deelan
ggg at zzz.it
Wed Mar 24 11:31:17 EST 2004
Richard A. Jones wrote:
> How do you send a POST to a url? I know how to do this with httplib but how
> do you do this using urllib2. For example:
>
> import urllib2
>
> url = http://123.8.37.87:4080/somewhere/something
> f = urllib2.urlopen(url)
>
>
> When I attempt this I get HTTP Error 400: HTTP method GET is not supported
> by this URL. Am I missing something?
try this:
url = "http://123.8.37.87:4080/somewhere/something"
data = {'some':'value'}
f = urllib2.urlopen(url, data=data)
if data is not None urllib2 automatically performs a POST
instead of GET.
--
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog <http://www.deelan.com/> .
More information about the Python-list
mailing list