0

当我在 Postman 中进行此 REST API 调用时,它会返回一个访问令牌 在此处输入图像描述 当我使用此代码在 Python 中尝试它时,我收到此错误

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)

有什么建议我做错了吗?

4

0 回答 0