python - 在开发 FastAPI 服务器时,如何像在 jupyter 笔记本中一样检查每个变量?
问题描述
我刚刚开始使用fastapi
python 开发简单的 ASGI 端点。我注意到处理程序函数代码只能在我使用uvicorn
. 例如,拿这个代码。
@app.post("/upload_dataset", tags=["DataFrame Loading Utilities"])
async def upload_dataset_to_server(file: UploadFile = File(...),
encoding='utf-8',
delimiter=',',
sheets='Sheet1'):
'''
Upload dataset. Add some more details about the parameters
'''
raw = await file.read()
try:
"""
TODO: XLSX still has some minor issues with saving
"""
if 'xlsx' in file.filename.split('.')[-1]:
df = pd.read_excel(io=raw, sheet_name=sheets)
filename = (file.filename).replace('xlsx', 'csv')
filepath = ml.folder_path + \
f'\\datastore\\dataset\\{filename}'
else:
content = str(raw, encoding=encoding)
data = StringIO(content)
df = pd.read_csv(filepath_or_buffer=data,
encoding=encoding, delimiter=delimiter)
filepath = ml.folder_path + \
f'\\datastore\\dataset\\{file.filename}'
df.to_csv(path_or_buf=filepath, index_label=False)
resp = ml.store_dataframe(df)
return resp
except UnicodeDecodeError as error:
raise HTTPException(
status_code=404,
detail=str(error)
)
有没有办法像在 jupyter notebook 中一样在函数中逐行运行,以熟悉每个对象代表的内容以及它们提供的接口?在我看来,如果不运行 uvicorn 模块并在服务器运行时打印日志,就无法调用函数或实际检查变量。
解决方案
推荐阅读
- manifest - 反应应用程序图标/清单未显示在gh页面上
- kubernetes - eks worker节点公网ip分配
- c# - 如何从以变量为键的 DataTable 生成 JSON
- ms-access - Access 数据库超过 5000 个项目,因此在 SharePoint 中不起作用
- apache-spark - spark-submit --files hdfs://file 缓存在驱动程序的 /tmp 中
- selenium - 在appium中获取数据提供者异常
- spring - Spring 集成 http-inbound-gateway / RequestMappingHandlerMapping
- javascript - 如果其他元素具有该类,如何停止将类添加到元素中?
- javascript - 循环 JSON 对象以检查给定值是否存在
- javascript - 如何从javascript转换维恩图代码