如何将数据插入FrappeClient中的子表?还有erpnext中的日期至日期字段吗?

发布于 2025-01-22 18:56:58 字数 2595 浏览 3 评论 0原文

我有两个问题:

1)我正在尝试将数据插入Doctype的儿童表“ Operator_Staff”。但是显示此错误。仅当我尝试将数据插入儿童表时才会遇到此错误。

Test Event Name
event

Response
{
  "errorMessage": "'body'",
  "errorType": "KeyError",
  "requestId": "0b615a56-3509-4a6f-90f2-ba1e5622560c",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 11, in lambda_handler\n    data = json.loads(event[\"body\"])\n"
  ]
}

Function Logs
START RequestId: 0b615a56-3509-4a6f-90f2-ba1e5622560c Version: $LATEST
[ERROR] KeyError: 'body'
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 11, in lambda_handler
    data = json.loads(event["body"])END RequestId: 0b615a56-3509-4a6f-90f2-ba1e5622560c
REPORT RequestId: 0b615a56-3509-4a6f-90f2-ba1e5622560c  Duration: 2.41 ms   Billed Duration: 3 ms   Memory Size: 128 MB Max Memory Used: 49 MB  Init Duration: 320.86 ms

Request ID
0b615a56-3509-4a6f-90f2-ba1e5622560c

这是我的代码:

def lambda_handler(event, context):
    
    client = FrappeClient("https://asc360-prod.frappe.cloud")
    client.authenticate("5600f29d5413f28", "b1e510514448494")
    
    data = json.loads(event["body"])
    
    doc = client.insert({
        "doctype": "Operator Policy Issued",
        "operator": data["operator"],
        "name1": data["name1"],
        "gender": data["gender"],
        "nationality": data["nationality"],
        "address": data["address"],
        "operator_staff": {
            "staff_name" : data["staff_name"],
            "activity_name": data["activity_name"]
            
        }
        })

2)如何通过FrappeClient插入日期字段?当我使用AWS lambda通过API插入数据时,我无法在那里使用Frappe。仅FrappeClient或DateTime模块。这是我在插入日期时遇到的错误。

Test Event Name
event

Response
{
  "errorMessage": "'body'",
  "errorType": "KeyError",
  "requestId": "cc50821d-d0b8-45e2-a44b-2c6acdad4c13",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 11, in lambda_handler\n    data = json.loads(event[\"body\"])\n"
  ]
}

Function Logs
START RequestId: cc50821d-d0b8-45e2-a44b-2c6acdad4c13 Version: $LATEST
[ERROR] KeyError: 'body'
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 11, in lambda_handler
    data = json.loads(event["body"])END RequestId: cc50821d-d0b8-45e2-a44b-2c6acdad4c13
REPORT RequestId: cc50821d-d0b8-45e2-a44b-2c6acdad4c13  Duration: 18.78 ms  Billed Duration: 19 ms  Memory Size: 128 MB Max Memory Used: 49 MB  Init Duration: 319.54 ms

Request ID
cc50821d-d0b8-45e2-a44b-2c6acdad4c13

I have two problems:

1) I'm trying to insert data to a child table, "operator_staff", of a doctype. But showing this error. Getting this error only when i try to insert data to child table.

Test Event Name
event

Response
{
  "errorMessage": "'body'",
  "errorType": "KeyError",
  "requestId": "0b615a56-3509-4a6f-90f2-ba1e5622560c",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 11, in lambda_handler\n    data = json.loads(event[\"body\"])\n"
  ]
}

Function Logs
START RequestId: 0b615a56-3509-4a6f-90f2-ba1e5622560c Version: $LATEST
[ERROR] KeyError: 'body'
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 11, in lambda_handler
    data = json.loads(event["body"])END RequestId: 0b615a56-3509-4a6f-90f2-ba1e5622560c
REPORT RequestId: 0b615a56-3509-4a6f-90f2-ba1e5622560c  Duration: 2.41 ms   Billed Duration: 3 ms   Memory Size: 128 MB Max Memory Used: 49 MB  Init Duration: 320.86 ms

Request ID
0b615a56-3509-4a6f-90f2-ba1e5622560c

This is my code:

def lambda_handler(event, context):
    
    client = FrappeClient("https://asc360-prod.frappe.cloud")
    client.authenticate("5600f29d5413f28", "b1e510514448494")
    
    data = json.loads(event["body"])
    
    doc = client.insert({
        "doctype": "Operator Policy Issued",
        "operator": data["operator"],
        "name1": data["name1"],
        "gender": data["gender"],
        "nationality": data["nationality"],
        "address": data["address"],
        "operator_staff": {
            "staff_name" : data["staff_name"],
            "activity_name": data["activity_name"]
            
        }
        })

2) How to insert date to a date field through frappeclient? As I'm using AWS Lambda to insert data through API I can't use Frappe there. Only FrappeClient or datetime module. This is error I'm getting while inserting date.

Test Event Name
event

Response
{
  "errorMessage": "'body'",
  "errorType": "KeyError",
  "requestId": "cc50821d-d0b8-45e2-a44b-2c6acdad4c13",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 11, in lambda_handler\n    data = json.loads(event[\"body\"])\n"
  ]
}

Function Logs
START RequestId: cc50821d-d0b8-45e2-a44b-2c6acdad4c13 Version: $LATEST
[ERROR] KeyError: 'body'
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 11, in lambda_handler
    data = json.loads(event["body"])END RequestId: cc50821d-d0b8-45e2-a44b-2c6acdad4c13
REPORT RequestId: cc50821d-d0b8-45e2-a44b-2c6acdad4c13  Duration: 18.78 ms  Billed Duration: 19 ms  Memory Size: 128 MB Max Memory Used: 49 MB  Init Duration: 319.54 ms

Request ID
cc50821d-d0b8-45e2-a44b-2c6acdad4c13

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文