在 Power BI 中设置 API 以从网站提取数据

Setting up an API in Power BI to pull data from website

我对 python 和 API 比较陌生。基本上,我在 Wufoo 中有一个表单,我目前正在手动将数据从中导出到 excel 文档中,以便构建 Power BI 报告。我一直在尝试直接与 Wufoo 建立网络连接,这样我就不再需要手动提取数据了。

我尝试在 Power BI 中使用从 Web 获取数据并输入 URL:http://{subdomain}.wufoo.com/api/v3/forms/{identifier}/fields.{format }) 更新子域并使用表单的散列作为标识符,并将格式设置为 json

但是报错: “(400):您的请求已被拒绝。请通过 HTTPS 发出此请求。”

我在下面的 Python(我使用的是 3.9.5 版)中构建了一些代码,虽然我能够使用它来提取数据并在我的代码编辑器(Komodo 编辑器)中打印出来), 但导航器中没有数据出现。我在这里做错了什么?

#!/usr/bin/python3

import urllib.request
import json

base_url = 'https://ewolford.wufoo.com/api/v3/'
username = 'API KEY'
password = 'password'

password_manager = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, base_url, username, password)
handler = urllib.request.HTTPBasicAuthHandler(password_manager)
opener = urllib.request.build_opener(handler)

urllib.request.install_opener(opener)

response = urllib.request.urlopen(base_url+'forms/hash/entries.json?sort=EntryId&sortDirection=DESC')

data = json.load(response)

print(json.dumps(data, indent=4, sort_keys=True))

添加最后一行以打印 pandas.dataframe。来自微软文档。 (强调我的):

The Power BI Python integration requires the installation of two Python packages:

Pandas. A software library for data manipulation and analysis. It offers data structures and operations for manipulating numerical tables and time series. Your imported data must be in a pandas data frame. A data frame is a two-dimensional data structure. For example, data is aligned in a tabular fashion in rows and columns.

import pandas as pd

{your code here}

data=json.load(response)

table=pd.DataFrame(data)

print(table)