0

I am sending simple GET request to backend API, that is built in python. I tried to get the headers from incoming request but not able to get it.
Here is how I am trying to get it
from flask import request request.headers.get('Authorization')
but every time it return None only.

Note: I am able to get all other headers like request.headers.get("Content-Type")

Sanjay
  • 1,958
  • 2
  • 17
  • 25

1 Answers1

-1

Am using requests approach which is the best.

see documentation links

First, You will need to Install and import requests via

pip install requests

You can see how I set authorization username and password variable to auth() so replace user and pass with your authorisation username and password. it it will work.

This code is an illustrations but it works

import json
import requests

resp1 = requests.get('https://api.github.com/user', auth=('user', 'pass'),  headers={
                       "Content-Type":"application/json",
                       "Accept": "application/json"
                      })



print('success')
print (resp1.status_code)
print (resp1.headers['content-type'])


#output any other response
content = json.loads(resp1.content)
print(content)
Nancy Moore
  • 2,322
  • 2
  • 21
  • 38