0

When I make this REST API call in Postman it comes back with an access token enter image description here When I attempt it in Python using this code, I get this error

import os
import requests
import json
import jmespath
import pandas as pd

from pprint import pprint
from pyapacheatlas.auth import ServicePrincipalAuthentication
from pyapacheatlas.core import PurviewClient, AtlasEntity, AtlasProcess, TypeCategory
from pyapacheatlas.core.typedef import *

from pyspark.sql import *
from pyspark.sql.functions import *
from pyspark.sql.types import *

tenant_id = "tenant-id"
client_id = "client-id"
client_secret = "client-secret"
data_catalog_name = "catalog-name"



url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/token"
payload= f'grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}&resource={resource_url}'
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}


response = requests.request("POST", url, headers=headers, data=payload)
access_token = json.loads(response.text) #['access_token']

print(access_token)

Any suggestions what I'm doing wrong?

jch
  • 187
  • 3
  • 17
  • I see ten headers in the postman request and only one (explicit) in your code. Can you show the requests that are sent from postman? – Mirronelli Mar 26 '21 at 21:06
  • Try to pass the url parameters via the params dictionary of requests.get instead of part of the url – DevLounge Mar 26 '21 at 21:13

0 Answers0