Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the content-type for POST requests in python-requests library?

One API I'm currently using specifies that I need a special content-type string. I don't know how do I set this in python-requests library

like image 1000
EnderSodium Avatar asked Sep 18 '15 11:09

EnderSodium


People also ask

How do you specify Content-Type in a POST request?

In a POST request, resulting from an HTML form submission, the Content-Type of the request is specified by the enctype attribute on the <form> element.

How do you pass Content-Type in Python?

To send the Content-Type header using Curl, you need to use the -H command-line option. For example, you can use the -H "Content-Type: application/json" command-line parameter for JSON data. Data is passed to Curl using the -d command-line option. It must match the provided content type.

What is Content-Type in Python?

The 'Content-Type: application/json' header tells the server that the request body contains a JSON string. The Python code was automatically generated for the Client Request Content Type Header example.

How do you pass POST request in Python?

To send a POST request using the Python Requests Library, you should call the requests. post() method and pass the target URL as the first parameter and the POST data with the data= parameter.


1 Answers

import requests  headers = {'Content-type': 'content_type_value'} r = requests.get(url, headers=headers) 
like image 180
Vikas Ojha Avatar answered Oct 09 '22 11:10

Vikas Ojha