简体   繁体   中英

Python Requests POST url encoded request not working

I am trying to make a post request to a url with Requests in Python. I am getting 500 ERROR message. I think the problem is in not properly encoding in content-type to x-www-form-urlencoded. If I try the same request in Postman it is working.

My Python code:

import requests


def get_pdf_link_by_post(url, payload):
    headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    r = requests.post(url, data=payload, headers=headers)
    print requests
    print "**************Headers*******************"
    print r.headers
    print r.content

def process_kat_causelist(date, adv_name):
    url = 'http://kat.kar.nic.in:8080/causelistsearch.jsp'
    for court_hall_idx in range(1, 4):
        court_hall = str(court_hall_idx)+'~Court Hall '+str(court_hall_idx)
        for list_idx in range(1, 7):
            list_num = str(list_idx)+'~List '+str(list_idx)
            payload = {'firstClDate': date, 'secondCldate': date, 'courthall': court_hall, 'lists': list_num}
            print payload
            get_pdf_link_by_post(url, payload)


process_kat_causelist('25/08/2015', 'ani')

Postman request:

在此处输入图片说明

在有效载荷中,secondCldate必须是secondClDate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM