cmberryau / pypowerbi Goto Github PK
View Code? Open in Web Editor NEWPython library for PowerBI
License: MIT License
Python library for PowerBI
License: MIT License
Hi Chris,
Any chance of adding support for Dataflows to the library?
Thanks,
Michael Stone
adal.adal_error.AdalError: Get Token request returned http error: 401 and server response: {"error":"invalid_client"
,"error_description":"AADSTS70002:
The request body must contain the following parameter: 'client_secret or client_assertion'.
I use code from example https://github.com/cmberryau/pypowerbi .
I change nothing except credentials.
Where I should use "client_secret"?
p.s. Sorry for bad english
Hi Chris,
While working on my project based on pypowerbi, I noticed ADAL has been deprecated for a while now. So I'm using the new MSAL library instead. One of the main tricky parts I noticed is that when passing the authentication token, that ADAL apparently used snake_case while MSAL uses CamelCase for its dictionary keys, this caused some exceptions being thrown by pypowerbi not finding the expected key (i.e. auth_token v.s. authToken)...
I'm just adding the issue here, to not forget about it. I can create a pull request for initial MSAL support.
One question, though, @cmberryau : should we maintain support in pypowerbi for ADAL, or can we drop support for it completely?
Announcement:
https://github.com/AzureAD/azure-activedirectory-library-for-python
Migration guide:
https://docs.microsoft.com/en-us/azure/active-directory/develop/migrate-python-adal-msal
First off all, this is an awesome project!
Do you have any plans to add refreshing of reports?
Hi,
these two functions are missing in the dataset class.
I created them locally, but not sure if I can integrate them.
Best,
Johanna
I tried using this library in python 2 but it fails due to the use of f-strings.
Install was done using pip install pypowerbi
Current workaround is to use future-fstrings package. Apply encoding cookie on top of each file in the package.
Hey Chris, I get a bug that I see is fixed in the github repo, but not pushed to Pypi. Can you please upgrade/upload latest version to Pypi? Thanks!
hi:
I am going to retrieve data from a report like:
So I tried like your example:
import adal
from pypowerbi.client import PowerBIClient
from pypowerbi.dataset import Column, Table, Dataset
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 = 'd9690d83-440d-48ec-ab79-69814b1fed25'
username = 'myemailaddress'
password = 'mypassword'
# first you need to authenticate using adal
logger.info('init context...')
context = adal.AuthenticationContext(authority=authority_url,
validate_authority=True,
api_version=None)
logger.info('init context done')
logger.info('acquire token...')
token = context.acquire_token_with_username_password(resource=resource_url,
client_id=client_id,
username=username,
password=password)
logger.info('got token: {}'.format(token))
# create your powerbi api client
logger.info('create client ...')
client = PowerBIClient(api_url, token)
logger.info('create client done.')
But I got the following error in acquire token:
[root@Server_130 try]# python3 a.py
20-09-04 16:27:43 [ INFO] init context...
20-09-04 16:27:43 [ INFO] init context done
20-09-04 16:27:43 [ INFO] acquire token...
20-09-04 16:27:43 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - Authority:Performing instance discovery: ...
20-09-04 16:27:43 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - Authority:Performing static instance discovery
20-09-04 16:27:43 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - Authority:Authority validated via static instance discovery
20-09-04 16:27:43 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - TokenRequest:Acquiring token with username password.
20-09-04 16:27:43 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - CacheDriver:finding with query keys: {'_clientId': '...', 'userId': '...'}
20-09-04 16:27:43 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - CacheDriver:Looking for potential cache entries: {'_clientId': '...', 'userId': '...'}
20-09-04 16:27:43 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - CacheDriver:Found 0 potential entries.
20-09-04 16:27:43 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - UserRealm:Performing user realm discovery at: ...
20-09-04 16:27:43 [DEBUG] Starting new HTTPS connection (1): login.windows.net:443
20-09-04 16:27:44 [DEBUG] https://login.windows.net:443 "GET /common/UserRealm/fei.ju%40nokia-sbel.com?api-version=1.0 HTTP/1.1" 200 136
20-09-04 16:27:44 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - UserRealm:User Realm Discovery Server returned this correlation_id: d874be3e-0eff-439b-a6d6-bf65d28b46fd
20-09-04 16:27:44 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - UserRealm:Discovery response:
{"ver":"1.0","account_type":"Unknown","cloud_instance_name":"microsoftonline.com","cloud_audience_urn":"urn:federation:MicrosoftOnline"}
20-09-04 16:27:44 [DEBUG] d874be3e-0eff-439b-a6d6-bf65d28b46fd - UserRealm:UserRealm response:
AccountType: unknown
FederationProtocol: None
FederationMetatdataUrl: None
FederationActiveAuthUrl: None
20-09-04 16:27:44 [ INFO] d874be3e-0eff-439b-a6d6-bf65d28b46fd - TokenRequest:get_token_func returned with error
Traceback (most recent call last):
File "a.py", line 54, in <module>
password=password)
File "/usr/local/lib/python3.6/site-packages/adal/authentication_context.py", line 164, in acquire_token_with_username_password
return self._acquire_token(token_func)
File "/usr/local/lib/python3.6/site-packages/adal/authentication_context.py", line 128, in _acquire_token
return token_func(self)
File "/usr/local/lib/python3.6/site-packages/adal/authentication_context.py", line 162, in token_func
return token_request.get_token_with_username_password(username, password)
File "/usr/local/lib/python3.6/site-packages/adal/token_request.py", line 286, in get_token_with_username_password
"Server returned an unknown AccountType: {}".format(self._user_realm.account_type))
adal.adal_error.AdalError: Server returned an unknown AccountType: unknown
Hi,
Thanks for your great library.
My only issue was that I could not import while # -- coding: future_fstrings -- was in the first line of each file.
After I removed everything worked perfectly.
Using in Anaconda running Python 3.7.3.
Cheers,
Michael
Hi,
do you have a road map of the end points you are planning to add? Are you aiming to cover all end points?
I was thinking about using the library to create/clone groups/workspace/apps and change their data sources.
Hi,
when running the example data in the README I am getting an error
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Here is the complete file:
JSONDecodeError Traceback (most recent call last)
in
15
16 # post your dataset!
---> 17 client.datasets.post_dataset(dataset)
~\anaconda3\lib\site-packages\pypowerbi\datasets.py in post_dataset(self, dataset, group_id)
130 # 201 - Created. The request was fulfilled and a new Dataset was created.
131 if response.status_code != 201:
--> 132 raise HTTPError(response, f'Post Datasets request returned http code: {response.json()}')
133
134 return Dataset.from_dict(json.loads(response.text))
~\anaconda3\lib\site-packages\requests\models.py in json(self, **kwargs)
898 # used.
899 pass
--> 900 return complexjson.loads(self.text, **kwargs)
901
902 @Property
~\anaconda3\lib\json_init_.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
355 parse_int is None and parse_float is None and
356 parse_constant is None and object_pairs_hook is None and not kw):
--> 357 return _default_decoder.decode(s)
358 if cls is None:
359 cls = JSONDecoder
~\anaconda3\lib\json\decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
~\anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Has someone come across this?
Cheers, Andi
First I would like to thank you for creating this package, saved me a lot of time. It seems currently relationship is not supported when posting a dataset. Will this feature be added in the future?
It seems that pypi.org doesn't have the latest updates of the github repo. Can you upgrade the version and push to pypi? Thanks!
Hi,
in datasets.delete_all_datasets the function detelete dataset is called with:
self.delete_dataset(group_id, dataset.id)
the definition of this function is
def delete_dataset(self, dataset_id, group_id=None):
So I guess group_id and dataset_id are in the wrong order. It should be self.delete_dataset(dataset.id, group_id, )
or
self.delete_dataset(group_id = group_id, dataset_id = dataset.id)
Best,
Johanna
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.