Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http POST Curl in python

I'm having trouble understanding how to issue an HTTP POST request using curl from inside of python.

I'm tying to post to facebook open graph. Here is the example they give which I'd like to replicate exactly in python.

curl -F 'access_token=...' \
     -F 'message=Hello, Arjun. I like this new API.' \
     https://graph.facebook.com/arjun/feed

Can anyone help me understand this?

like image 300
evanlivingston Avatar asked Oct 19 '11 20:10

evanlivingston


1 Answers

You can use httplib to POST with Python or the higher level urllib2

import urllib

params = {}

params['access_token'] = '*****'
params['message'] = 'Hello, Arjun. I like this new API.'

params = urllib.urlencode(params)
f = urllib.urlopen("https://graph.facebook.com/arjun/feed", params)
print f.read()

There is also a Facebook specific higher level library for Python that does all the POST-ing for you.

https://github.com/pythonforfacebook/facebook-sdk/

https://github.com/facebook/python-sdk

like image 140
kichik Avatar answered Oct 21 '22 13:10

kichik