GithubHelp home page GithubHelp logo

Comments (2)

bapat-atharva avatar bapat-atharva commented on July 27, 2024

Hi @Cagataydemirkol,

This approach you are using is used for App Owns Data. With this access-token you will be able to generate embed tokens using the PBI Rest APIs. But embed-tokens are not supported currently in powerbi-jupyter.

You could use master-user approach and specify a username(email) and password in the request with grant_type as 'password'. With this access token you should be able to embed any of the reports.

from powerbi-jupyter.

mhadi4194 avatar mhadi4194 commented on July 27, 2024

@bapat-atharva our organization will not allow master user. Our only option is Service Principal for authentication. The service principal has member role in powerbi the workspace of report and dataset.
I am trying to download data from PowerBI visuals programmatically by running code in Google Cloud Function.

def get_powerbi_access_token(secrets: dict, scopes: list =None):
    from msal import ConfidentialClientApplication
    client_id = secrets['client_id']
    client_secret = secrets['client_secret']
    tenant_id = secrets['tenent_id']
    authority_url = f'https://login.microsoftonline.com/{tenant_id}'
    
    app = ConfidentialClientApplication(client_id,client_credential=client_secret,authority=authority_url)
    if not scopes:
        scopes = ['https://analysis.windows.net/powerbi/api/.default']
        
    return app.acquire_token_for_client(scopes=scopes)

access_token = get_powerbi_access_token(secrets)['access_token']
report = Report(group_id=group_id, report_id=report_id, auth=access_token)
report

It is throwing below error while running in notebook

Exception                                 Traceback (most recent call last)
File /opt/miniconda3/envs/powerbi/lib/python3.9/site-packages/ipywidgets/widgets/widget.py:773, in Widget._handle_msg(self, msg)
    771         if 'buffer_paths' in data:
    772             _put_buffers(state, data['buffer_paths'], msg['buffers'])
--> 773         self.set_state(state)
    775 # Handle a state request.
    776 elif method == 'request_state':

File /opt/miniconda3/envs/powerbi/lib/python3.9/site-packages/ipywidgets/widgets/widget.py:655, in Widget.set_state(self, sync_data)
    652 if name in self.keys:
    653     from_json = self.trait_metadata(name, 'from_json',
    654                                     self._trait_from_json)
--> 655     self.set_trait(name, from_json(sync_data[name], self))

File /opt/miniconda3/envs/powerbi/lib/python3.9/contextlib.py:126, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    124 if typ is None:
    125     try:
--> 126         next(self.gen)
    127     except StopIteration:
    128         return False

File /opt/miniconda3/envs/powerbi/lib/python3.9/site-packages/traitlets/traitlets.py:1498, in HasTraits.hold_trait_notifications(self)
   1496 for changes in cache.values():
   1497     for change in changes:
-> 1498         self.notify_change(change)

File /opt/miniconda3/envs/powerbi/lib/python3.9/site-packages/ipywidgets/widgets/widget.py:701, in Widget.notify_change(self, change)
    698     if name in self.keys and self._should_send_property(name, getattr(self, name)):
    699         # Send new state to front-end
    700         self.send_state(key=name)
--> 701 super().notify_change(change)

File /opt/miniconda3/envs/powerbi/lib/python3.9/site-packages/traitlets/traitlets.py:1513, in HasTraits.notify_change(self, change)
   1511 def notify_change(self, change):
   1512     """Notify observers of a change event"""
-> 1513     return self._notify_observers(change)

File /opt/miniconda3/envs/powerbi/lib/python3.9/site-packages/traitlets/traitlets.py:1560, in HasTraits._notify_observers(self, event)
   1557 elif isinstance(c, EventHandler) and c.name is not None:
   1558     c = getattr(self, c.name)
-> 1560 c(event)

File /opt/miniconda3/envs/powerbi/lib/python3.9/site-packages/powerbiclient/report.py:202, in Report._on_error(self, change)
    200 if (change['new'] is not self.INIT_ERROR_DEFAULT_STATE):
    201     self._init_error = self.INIT_ERROR_DEFAULT_STATE
--> 202     raise Exception(change['new'])

Exception: LoadReportFailed - Fail to initialize - Could not resolve cluster

Will this approach work to automate data export from powerbi reports to excel using functions on Azure or GCP?

from powerbi-jupyter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.