Tutorial by Examples

from requests import post foo = post('http://httpbin.org/post', data = {'key':'value'}) Will perform a simple HTTP POST operation. Posted data can be inmost formats, however key value pairs are most prevalent. Headers Headers can be viewed: print(foo.headers) An example response: {'Cont...
from requests import post payload = {'key1' : 'value1', 'key2' : 'value2' } foo = post('http://httpbin.org/post', data=payload) To pass form encoded data with the post operation, data must be structured as dictionary and supplied as the data parameter. If the data d...
With the Requests module,its is only necessary to provide a file handle as opposed to the contents retrieved with .read(): from requests import post files = {'file' : open('data.txt', 'rb')} foo = post('http://http.org/post', files=files) Filename, content_type and headers can also be set:...
Response codes can be viewed from a post operation: from requests import post foo = post('http://httpbin.org/post', data={'data' : 'value'}) print(foo.status_code) Returned Data Accessing data that is returned: foo = post('http://httpbin.org/post', data={'data' : 'value'}) print(foo.text)...
Simple HTTP Authentication Simple HTTP Authentication can be achieved with the following: from requests import post foo = post('http://natas0.natas.labs.overthewire.org', auth=('natas0', 'natas0')) This is technically short hand for the following: from requests import post from requests.au...
Each request POST operation can be configured to use network proxies HTTP/S Proxies from requests import post proxies = { 'http': 'http://192.168.0.128:3128', 'https': 'http://192.168.0.127:1080', } foo = requests.post('http://httpbin.org/post', proxies=proxies) HTTP Basic Authe...

Page 1 of 1