make a http request with a custom header in python

To make a HTTP request with a custom header in Python, you can use the requests library. Here's an example code:

main.py
import requests

# API endpoint and custom header
url = "https://api.example.com"
headers = {"Authorization": "Bearer your-auth-token"}

# Make the request with `requests.get` or `requests.post`
response = requests.get(url, headers=headers)

# Print the response
print(response.text)
284 chars
12 lines

In this code, we define our endpoint URL and the custom header we want to send. We then make the request using requests.get or requests.post and pass in the URL and headers as parameters. Finally, we print the response returned by the API.

gistlibby LogSnag