python requests post text/plain

Python Requests Post text/plain

If you need to send data in a plain text format to a server using Python, you can use the requests library. The requests library is a popular Python library for making HTTP requests. In this guide, we will show you how to use the method to send data in a plain text format.

Step 1: Install requests Library

If you haven't installed the requests library, you can install it using pip:

pip install requests

Step 2: Import requests Library

After installing requests library, you need to import it in your Python script:

import requests

Step 3: Send POST Request with Plain Text Data

You can send a POST request with plain text data using the method:

url = ''
data = 'Hello, World!'
response =, data=data, headers={'Content-Type': 'text/plain'})

  • url: The URL of the API endpoint where you want to send the POST request.
  • data: The plain text data that you want to send with the request.
  • headers: The headers of the request. In this case, we set the Content-Type header to text/plain.

The response.status_code variable contains the HTTP status code of the response, and the response.text variable contains the content of the response.


In this guide, we showed you how to send plain text data using the method in Python. By using this method, you can easily send plain text data to an API endpoint and get the response back in your Python script.