0

我已经成功地在 PowerSchool 中设置了我需要的插件来通过 Python 查询表,如下所示。我查看了 PowerSchool 库文档中的示例,但无法使用相同的方法成功查询特定表(同时应用任何过滤器)。我只能获取整个表(使用 SQL 查询时)或“HTTPError: 400 Client Error: Bad Request for url: ...”(使用参数时)。

import powerschool
import pandas as pd

client_id =  'client id goes here'
client_secret = 'client secret goes here'
my_credentials = (client_id, client_secret)
host_name = 'host name goes here'
ps = powerschool.PowerSchool(host=host_name, auth=my_credentials)
st = ps.get_schema_table('students') 

# I have tried each of these and they all return the entire table
sql = '''SELECT * FROM STUDENTS WHERE last_name IN ('SMITH', 'JOHNSON')'''
params = {'last_name':'SMITH',
          'projection':'last_name'}

stData = st.query(**params)
df = pd.DataFrame.from_dict(stData)

stData2 = st.query(body=sql)
df = pd.DataFrame.from_dict(stData2)

提前致谢!

4

1 回答 1

0

您链接的文档给出了这个例子:

params = {
    'q': 'id=ge=10000',
    'projection': 'school_number,abbreviation',
}
schools_table.query(**params)

您的代码可以:

params = {'last_name':'SMITH',
          'projection':'last_name'}

stData = st.query(**params)
df = pd.DataFrame.from_dict(stData)

在我看来,'last_name':'SMITH'应该更接近'q': 'id=ge=10000'. 我不知道 PowerSchool 但也许'q': 'last_name=SMITH'

于 2022-01-17T10:10:15.560 回答