在圣杯中使用pynamodb可以得到InternalServerE

2024-05-13 01:14:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用Chalice框架编写一个项目。我需要与DynamoDB交互,所以我想使用库来简化代码。我试图使用pynamodb,但我不知道我遗漏了什么。在

在应用程序副本在

from chalice import Chalice
from chalicelib import AgentSkill

app = Chalice(app_name='helloworld2')

# this works
@app.route('/')
def index():
    return {'hello': 'world'}

# this throws error
@app.route('/skill')
def addSkill():
    f not AgentSkill.exists():
        AgentSkill.create_table(read_capacity_units=1,
                            write_capacity_units=1, wait=True)

    agsk = AgentSkill()
    agsk.agentID = 1
    agsk.save()
    return {'success': 'true'}

chalicelib/初始化.py

^{pr2}$

查利塞利布/AgentSkill.py在

from pynamodb.models import Model
from pynamodb.attributes import (UnicodeAttribute, NumberAttribute)

class AgentSkill(Model):
    class Meta:
        table_name = 'agent_skill'
        region = 'us-west-2'

    agentID =  NumberAttribute(hash_key=True)

在要求.txt在

pynamodb

是我缺少了什么,还是需要在要求.文本文件?在

没有pynamodb在要求.txt文件我会得到一个内部服务器错误的每一个调用。加上它,我现在至少可以让hello world做出回应。/技能然后给出:

{
    "Code": "InternalServerError",
    "Message": "An internal server error occurred."
}

我不知道从这里到哪里去?在


Tags: namefromimportapphelloworldreturndef