Bunny Rabbit
Bunny Rabbit

Reputation: 8411

how to make post requests in python/django?

as described in http://developers.facebook.com/docs/api#publishing i want to make a post request to update a users status .How do i make post requests in python / django?

Upvotes: 2

Views: 4382

Answers (3)

Asad Shakeel
Asad Shakeel

Reputation: 2285

There is another way using python famous library Requests

import requests

data = {
  "username": "user",
  "password": "pass",
}

URL = 'http://example.com'
r = requests.post(URL, data=data)

PS: copied from here

Upvotes: 0

Ashok
Ashok

Reputation: 10603

import urllib2

urllib2.urlopen('http://example.com', 'a=1&b=2')

will send a post request to http://example.com, with parameters a=1 and b=2

Upvotes: 5

Alex Martelli
Alex Martelli

Reputation: 881477

Django has little to do with it, but urrlib2.urlopen is a simple enough way to POST. Just call it with a second parameter data (the first one is the URL you're addressing) that has the application/x-www-form-urlencoded formatted data you're posting (as the docs say, use urllib.urlencode to encode a mapping, typically a dictionary, in that way).

Upvotes: 6

Related Questions