
get_embed_params_for_multiple_reports
Publicado por Albert (1 intervención) el 16/05/2023 11:38:51
¿Alguien sabe por qué obtengo el siguiente error cuando hago power bi embedded?
Inserto el código de múltiples reports
pbiembedservice.py
con el código de informe único funciona bien.
app.py
Error:
gracias.
Inserto el código de múltiples reports
pbiembedservice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def get_embed_params_for_multiple_reports(self, workspace_id, report_ids, additional_dataset_ids=None):
'''Get embed params for multiple reports for a single workspace
Args:
workspace_id (str): Workspace Id
report_ids (list): Report Ids
additional_dataset_ids (list, optional): Dataset Ids which are different than the ones bound to the reports. Defaults to None.
Returns:
EmbedConfig: Embed token and Embed URLs
'''
# Note: This method is an example and is not consumed in this sample app
dataset_ids = []
# To store multiple report info
reports = []
for report_id in report_ids:
report_url = f'https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/reports/{report_id}'
api_response = requests.get(report_url, headers=self.get_request_header())
if api_response.status_code != 200:
abort(api_response.status_code, description=f'Error while retrieving Embed URL\n{api_response.reason}:\t{api_response.text}\nRequestId:\t{api_response.headers.get("RequestId")}')
api_response = json.loads(api_response.text)
report_config = ReportConfig(api_response['id'], api_response['name'], api_response['embedUrl'])
reports.append(report_config.__dict__)
dataset_ids.append(api_response['datasetId'])
# Append additional dataset to the list to achieve dynamic binding later
if additional_dataset_ids is not None:
dataset_ids.extend(additional_dataset_ids)
embed_token = self.get_embed_token_for_multiple_reports_single_workspace(report_ids, dataset_ids, workspace_id)
embed_config = EmbedConfig(embed_token.tokenId, embed_token.token, embed_token.tokenExpiry, reports)
return json.dumps(embed_config.__dict__)
con el código de informe único funciona bien.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def get_embed_params_for_single_report(self, workspace_id, report_id, additional_dataset_id=None):
'''Get embed params for a report and a workspace
Args:
workspace_id (str): Workspace Id
report_id (str): Report Id
additional_dataset_id (str, optional): Dataset Id different than the one bound to the report. Defaults to None.
Returns:
EmbedConfig: Embed token and Embed URL
'''
report_url = f'https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/reports/{report_id}'
api_response = requests.get(report_url, headers=self.get_request_header())
if api_response.status_code != 200:
abort(api_response.status_code, description=f'Error while retrieving Embed URL\n{api_response.reason}:\t{api_response.text}\nRequestId:\t{api_response.headers.get("RequestId")}')
api_response = json.loads(api_response.text)
report = ReportConfig(api_response['id'], api_response['name'], api_response['embedUrl'])
dataset_ids = [api_response['datasetId']]
# Append additional dataset to the list to achieve dynamic binding later
if additional_dataset_id is not None:
dataset_ids.append(additional_dataset_id)
embed_token = self.get_embed_token_for_single_report_single_workspace(report_id, dataset_ids, workspace_id)
embed_config = EmbedConfig(embed_token.tokenId, embed_token.token, embed_token.tokenExpiry, [report.__dict__])
return json.dumps(embed_config.__dict__)
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from services.pbiembedservice import PbiEmbedService
from utils import Utils
from flask import Flask, render_template, send_from_directory
import json
import os
# Initialize the Flask app
app = Flask(__name__)
# Load configuration
app.config.from_object('config.BaseConfig')
@app.route('/')
def index():
'''Returns a static HTML page'''
return render_template('index.html')
@app.route('/getembedinfo', methods=['GET'])
def get_embed_info():
'''Returns report embed configuration'''
config_result = Utils.check_config(app)
if config_result is not None:
return json.dumps({'errorMsg': config_result}), 500
try:
embed_info = PbiEmbedService().get_embed_params_for_multiple_reports(app.config['WORKSPACE_ID'], ["d12aa9d3-5674-4acf-8c14-17ac454r9824","1f4c3e4e-da6a-4199-bd5f-2194456be195"])
return embed_info
except Exception as ex:
return json.dumps({'errorMsg': str(ex)}), 500
@app.route('/favicon.ico', methods=['GET'])
def getfavicon():
'''Returns path of the favicon to be rendered'''
return send_from_directory(os.path.join(app.root_path, 'static'), 'img/favicon.ico', mimetype='image/vnd.microsoft.icon')
if __name__ == '__main__':
app.run()
Error:
1
2
3
4
Error Details:
400 Bad Request: Error while retrieving Embed token
Bad Request: {"error":{"code":"InvalidRequest","message":"datasets is duplicated in required 93be0a80-c741-4def-aec2-948987794b27"}}
RequestId: faa20ca3-29ea-4e34-ad02-3dca4a16b570
gracias.
Valora esta pregunta


0