【解決方法】REST APIを使用してPowerBIでレポートを作成中にエラーが発生する


Failed to create report. Error: b'{\r\n  "error":{\r\n    "code":"","message":"No HTTP resource was found that matches the request URI \'http://wabi-india-central-a-primary-redirect.analysis.windows.net/v1.0/myorg/groups/me/reports\'."\r\n  }\r\n}'
None

これは私が得ているエラーです

私が試したこと:

import requests
import json

# Set your Power BI REST API endpoint URLs
base_url = "https://api.powerbi.com/v1.0/myorg"
reports_url = f"{base_url}/groups/{group_id}/reports"

# Set your authentication token
access_token = "YOUR_ACCESS_TOKEN"

# Set the group ID where the report will be created
group_id = "YOUR_GROUP_ID"

# Create a report definition
report_definition = {
    "name": "My Report",
    "datasetId": "EXISTING_DATASET_ID"
}

# Create the report in the group
def create_report():
    create_report_url = reports_url
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json"
    }
    payload = {
        "name": report_definition["name"],
        "datasetId": report_definition["datasetId"]
    }
    response = requests.post(create_report_url, headers=headers, json=payload)
    if response.status_code == 201:
        report_id = response.json()["id"]
        print("Report created successfully. ID:", report_id)
        return report_id
    else:
        print("Failed to create report. Error:", response.content)
        return None

# Run the function to create the report
create_report()

これが私が試したことです

解決策 1

無効な文字「f」が含まれています

headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}

への変更:

headers = {
    "Authorization": "Bearer {access_token}",
    "Content-Type": "application/json"
}

コメント

タイトルとURLをコピーしました