【问题标题】:IndexError: tuple index out of range while running both rasa shell and actions.py fileIndexError:运行 rasa shell 和 actions.py 文件时元组索引超出范围
【发布时间】:2020-10-24 00:02:50
【问题描述】:

这是我的 actions.py 文件:-

from rasa_sdk import Action, Tracker 从 rasa_sdk.executor 导入 CollectingDispatcher 从 rasa_sdk.events 导入 SlotSet 导入json

类 ActionHr(Action): 定义名称(自我): print('在自我方法中') 返回'action_leave'

def run (self, dispatcher, tracker, domain):
    print('in run method')
    i = tracker.get_slot('name')
    print(i)
    with open('data1.txt') as json_file:
        data = json.loads(json_file.read())
        
        for result in data['current']:
            print('name'+ result['name'])
            if result['name'].lower() == i.lower():
                print('name Found')
                name = result['name']
                SickLeave = result['Sick Leaves']
                CasualLeave = result['Casual Leaves']
                TotalLeave = result['Total Leaves']
                LeavesLeft = result['Leaves Left']
    response ="""The Leaves left for name {} is {} . You took {} casual leaves and {} sick leaves.""".format(SickLeave,CasualLeave,TotalLeave)
    
    print(response)
                    
    dispatcher.utter_message(response)
    return [SlotSet('name',i)]
    

这是我的 json 文件:

{ “当前的”: [ { “名称”:“韦丹特”, “病叶”:3, “散叶”:1, “总叶数”:4, “离开”:14 }, { “名称”:“德巴斯米塔”, “病叶”:1, “散叶”:5, “总叶子”:6, “离开”:12 }, { “名称”:“阿科帕纳”, “病叶”:4, “散叶”:2, “总叶子”:6, “离开”:12 }, { “名称”:“安基塔”, “病叶”:1, “休闲叶子”:0, “总叶数”:1, “离开”:17 }, { “名称”:“萨那”, “病叶”:0, “散叶”:6, “总叶子”:6, “离开”:12 } ] }

当我同时运行 rasa run 操作和 rasa shell 时,当我试图获取输入名称的休假详细信息时出现此错误..

这是我的错误:

在运行方法中 德巴斯米塔 名称Vedant 名称Debasmita 名称找到 名称Akoparna 名称Ankita 名称Sana 处理 uri 时发生异常:'http://localhost:5055/webhook' 回溯(最近一次通话最后): 文件“c:\users\debasmita\anaconda3\envs\hr\lib\site-packages\sanic\app.py”,第 976 行,在 handle_request 响应 = 等待响应 Webhook 中的文件“c:\users\debasmita\anaconda3\envs\hr\lib\site-packages\rasa_sdk\endpoint.py”,第 102 行 结果 = 等待 executor.run(action_call) 运行中的文件“c:\users\debasmita\anaconda3\envs\hr\lib\site-packages\rasa_sdk\executor.py”,第 387 行 事件 = 动作(调度程序、跟踪器、域) 文件“E:\New\actions.py”,第 57 行,运行中 response ="""留给姓名 {} 的叶子是 {}。您请了 {} 临时休假和 {} 病假。""".format(SickLeave,CasualLeave,TotalLeave) IndexError: 元组索引超出范围

请帮帮我。

【问题讨论】:

    标签: python rasa-nlu rasa-core rasa


    【解决方案1】:

    问题似乎出在您尝试“格式化”结果的那一行:

    response ="""The Leaves left for name {} is {} . You took {} casual leaves and {} sick leaves.""".format(SickLeave,CasualLeave,TotalLeave)
    

    请注意,您有 4 个大括号和只有 3 个参数,因此使用 'format' 的替换过程无法完成,我将错误重现如下:

    请尝试添加缺少的参数以查看错误是否仍然存在。

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 2013-07-28
      • 2018-11-16
      • 2017-07-12
      • 2013-12-16
      • 2021-12-21
      • 2014-08-01
      • 2021-04-19
      相关资源
      最近更新 更多