I've used a variety of python HTTP libs in the past, and I've settled on requests as my favourite. Existing libs had pretty useable interfaces, but code can end up being a few lines too long for simple operations. A basic PUT in requests looks like:
payload = {'username': 'bob', 'email': '[email protected]'}
>>> r = requests.put("http://somedomain.org/endpoint", data=payload)
You can then check the response status code with:
r.status_code
or the response with:
r.content
Requests has a lot synactic sugar and shortcuts that'll make your life easier.
Answer from John Bear on Stack OverflowVideos
I've used a variety of python HTTP libs in the past, and I've settled on requests as my favourite. Existing libs had pretty useable interfaces, but code can end up being a few lines too long for simple operations. A basic PUT in requests looks like:
payload = {'username': 'bob', 'email': '[email protected]'}
>>> r = requests.put("http://somedomain.org/endpoint", data=payload)
You can then check the response status code with:
r.status_code
or the response with:
r.content
Requests has a lot synactic sugar and shortcuts that'll make your life easier.
import urllib2
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request('http://example.org', data='your_put_data')
request.add_header('Content-Type', 'your/contenttype')
request.get_method = lambda: 'PUT'
url = opener.open(request)
» pip install requests
Morning
I am currently trying to do some work on the Facebook API and in the following link it gives examples of the curl requests needed to update the data within the API.
Facebook Documentation
Given a dataframe of the data I’d like to upload, What is the best way to build these requests out in Python? I.e what is the best way to build these dictionaries using a dataframe?
Thanks
https://www.youtube.com/watch?v=tb8gHvYlCFs&t=374s
I am watching this vid, all excited to learn requests, but I don't really understand nearly anything, like what is r.content doing, or the r.json() function does I also don't get what
what is in r.content, it returns things, but I don't really understand what these things are, r.text returns a dictionary of args, headers, origin etc but I don't really get how this information is useful.
r.get, r.post, or r.put really do I am really sorry for this but if someone could link an article or a little video that explains what the content is, like I am not sure what to search for.