ADAL Python 刷新 PowerBI 数据集

ADAL Python to Refresh PowerBI dataset(ADAL Python 刷新 PowerBI 数据集)
本文介绍了ADAL Python 刷新 PowerBI 数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 Azure 文档中发现了一段代码,它允许在没有 MFA 的情况下获取凭据.但我想知道是否可以使用它连接到 PowerBI API.

I found a piece of code on Azure documentation that allows getting credentials without MFA. But I'm wondering if is possible to use it to connect to PowerBI API.

我正在使用的代码是:

import adal
import requests
from msrestazure.azure_active_directory import AADTokenCredentials

def authenticate_client_key():

    authority_host_uri = 'https://login.microsoftonline.com'
    tenant = 'tenant'
    authority_uri = authority_host_uri + '/' + tenant
    resource_uri = 'https://management.core.windows.net/'
    client_id = 'clientid'
    client_secret = 'client-secret'

    context = adal.AuthenticationContext(authority_uri, api_version=None)
    mgmt_token = context.acquire_token_with_client_credentials(resource_uri, client_id, client_secret)
    credentials = AADTokenCredentials(mgmt_token, client_id)

    return credentials

来源:https://azure.microsoft.com/en-us/resources/samples/data-lake-analytics-python-auth-options/

根据写在PowerShell上的代码,目的是将access_token插入到后面的POST请求的header中

According to the code written on PowerShell, the aim is to insert the access_token into the header of the following POST request

POST https://api.powerbi.com/v1.0/myorg/groups/me/datasets/{dataset_id}/refreshes

POST https://api.powerbi.com/v1.0/myorg/groups/me/datasets/{dataset_id}/refreshes

来源:https://powerbi.microsoft.com/en-us/blog/announcing-data-refresh-apis-in-the-power-bi-service/

我尝试在 POST 请求中使用凭据,但似乎不起作用.

I have tried to use the credentials into the POST request, but seems is not working.

我试过了

url = 'https://api.powerbi.com/v1.0/myorg/groups/me/datasets/datasetid/refreshes'
requests.post(url,data=mgmt_token)

这两个代码可以合并吗?

Is it possible to merge this two codes?

问候,

推荐答案

您可以使用 pypowerbi 包刷新 Power BI 数据集,也可以通过检查代码来检查如何自己执行此操作.https://github.com/cmberryau/pypowerbi

You can use the pypowerbi package to refresh Power BI datasets or you can check how to do it yourself by inspecting the code. https://github.com/cmberryau/pypowerbi

pip install pypowerbi

import adal
from pypowerbi.client import PowerBIClient

# you might need to change these, but i doubt it
authority_url = 'https://login.windows.net/common'
resource_url = 'https://analysis.windows.net/powerbi/api'
api_url = 'https://api.powerbi.com'

# change these to your credentials
client_id = '00000000-0000-0000-0000-000000000000'
username = 'someone@somecompany.com'
password = 'averygoodpassword'

# first you need to authenticate using adal
context = adal.AuthenticationContext(authority=authority_url,
                                     validate_authority=True,
                                     api_version=None)

# get your authentication token
token = context.acquire_token_with_username_password(resource=resource_url,
                                                     client_id=client_id,
                                                     username=username,
                                                     password=password)

# create your powerbi api client
client = PowerBIClient(api_url, token)

# Refresh the desired dataset (dataset and group IDs can be taken from the browser URL)
client.datasets.refresh_dataset(dataset_id='data-set-id-goes-here',
                                notify_option='MailOnCompletion',
                                group_id='group-id-goes-here')

这篇关于ADAL Python 刷新 PowerBI 数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

python arbitrarily incrementing an iterator inside a loop(python在循环内任意递增迭代器)
Joining a set of ordered-integer yielding Python iterators(加入一组产生 Python 迭代器的有序整数)
Iterating over dictionary items(), values(), keys() in Python 3(在 Python 3 中迭代字典 items()、values()、keys())
What is the Perl version of a Python iterator?(Python 迭代器的 Perl 版本是什么?)
How to create a generator/iterator with the Python C API?(如何使用 Python C API 创建生成器/迭代器?)
Python generator behaviour(Python 生成器行为)