Skip to content

Send POST to server via python-requests

April 15th, 2014 - Software(1 min)

The other day I’ve had a question asked:

How do you send a form data to a server and get the reply?

My solution involves python-requests:

__author__ = 'Laur IVAN'

import requests

proxies = {
    'http': 'http://.../',
    'https': 'http://.../'

payload = {
    'Sentence': 'There was a little red hat.',
    'Constituents': 'on',
    'NullLinks': 'on',
    'AllLinkages': 'on',
    'LinkDisplay': 'on',
    'ShortLegth': '6',
    'PageFile': '/docs/submit-sentence-4.html',
    'InputFile': "/scripts/input-to-parser",
    'Maintainer': "[email protected]"

r =
    data=payload, proxies=proxies)

print r.text

r.text contains the reply HTML page, which then needs to be processed via e.g. python’s DOM processing module or BeautifulSoup (if you’re looking for something more tolerant).


Share on

A little experiment: