jupyter形式执行任务
请求头(Request Header)
请参考API 使用指南
请求参数(Request Parameters)
| 名称 | 类型 | 必须 | 位置 | 描述 |
|---|---|---|---|---|
| workspace_id | string | 是 | path | 工作空间id,获取方式可以参考快速开始 |
| sandbox_group_id | string | 是 | path | 沙盒组id |
| execute_content | object | 是 | body | 执行内容 |
其中execute_content的参数如下:
| 名称 | 类型 | 必须 | 位置 | 描述 |
|---|---|---|---|---|
| sandbox_id | string | 否 | body | 沙盒实例id,若不传入,系统将从沙盒组中任选一个沙盒实例进行任务执行 |
| cells | array[string] | 是 | body | 要执行的代码块数组 |
| cell_timeout | integer | 否 | body | 单个cell最长执行时间,单位为秒,可设置范围为(0,300],默认值为60,该参数值不可大于total_timeout |
| total_timeout | integer | 否 | body | 所有代码块执行超时时间,单位为秒,可设置范围为(0,300],默认值为45秒。该参数仅设置接口中代码执行部分的超时,整体接口超时时间为10分钟,包含数据上传下载以及代码执行。 |
| kernel | string | 否 | body | 指定 kernel 类型,默认 python3 |
| upload_files | object | 否 | body | 上传文件内容,key:value形式,其中key中需要填写文件在沙盒中的存放路径,value为文件base64内容 |
| fetch_files | array | 否 | body | 任务执行后需要获取的文件路径 |
请求示例(Request Example)
curl -L -X POST 'https://sandbox.cn-sh-01.sensecoreapi.cn/studio/sandbox/v1/workspaces/01993ca4-edfa-7382-8161-43a4919681ab/sandboxGroups/c8e381e5-491c-47cf-842b-aacf914a8c35:jupyterExecute' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
--data-raw '{
"execute_content": {
"cells":["print('\''Hello World!'\'')"],
"kernel":"python3"
}
}'
响应(Response)
异常情况请参考异常响应说明
| 字段 | 类型 | 描述 |
|---|---|---|
| sandbox_id | string | 执行沙箱的 ID |
| cells | array[object] | 每个cell执行结果 |
| driver | objcet | 驱动执行信息 |
| files | object | 下载的文件内容,key:value形式,key中为文件路径,value中为文件内容base64编码。若为空,则不返回该字段 |
其中,driver的参数如下:
| 字段 | 类型 | 描述 |
|---|---|---|
| status | string | 执行状态 |
| return_code | int32 | 返回码 |
| execution_time | double | 执行时长 |
| stdout | string | 标准输出 |
| stderr | string | 标准错误 |
其中,cells中每个元素的参数如下:
| 字段 | 类型 | 描述 |
|---|---|---|
| stdout | string | 该cell的标准输出 |
| stderr | string | 该cell标准错误 |
| display | array[object] | notebook display 输出(图表、表格等) |
| error | array[object] | 执行错误对象数组 |
其中,display中每个元素的参数如下:
| 字段 | 类型 | 描述 |
|---|---|---|
| data | objcet | MIME类型到内容的映射,如 {"text/plain": "123", "image/png": "..."} |
其中,error中每个元素的参数如下:
| 字段 | 类型 | 描述 |
|---|---|---|
| ename | string | 错误类型名称 |
| evalue | string | 错误值/消息 |
| traceback | array[string] | 错误追踪信息 |
响应示例(Response Example)
- 正常响应
{
"sandbox_id": "29e155c9-aba3-453e-9525-1ef5248192fd",
"driver": {
"status": "Finished",
"execution_time": 1.2201602458953857,
"stdout": "config: \n{\n \"kernel\": \"python3\",\n \"cells\": [\n \"print('Hello World!')\"\n ],\n \"cell_timeout\": 60.0,\n \"total_timeout\": 60.0\n}\n"
},
"cells": [
{
"stdout": "Hello World!\n"
}
]
}