我已经检查了有关此问题的所有其他相关帖子,但是在尝试执行以下操作时,对我来说没有任何实际作用:
经过一系列修改后,我当前的代码如下:
class ActionRequestTasks(Action):
def name(self):
return "action_request_tasks"
@staticmethod
def json2obj(data):
return json.loads(data, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
def run(self, dispatcher, tracker: DialogueStateTracker, domain):
response = requests.get('url', headers=headers)
tasks_wrapper = self.json2obj(response.text)
data = tasks_wrapper.Data
first_message = "You have {} delayed tasks, I will help you to go through all of them".format(len(data))
dispatcher.utter_message(first_message)
for task in data:
task_message = "Task Title {}\nComplete percentage {}\nStart Date {}\nFinish Date{}".format(task.Title,
task.PercentComplete,
task.StartDate,
task.FinishDate)
dispatcher.utter_message(task_message)
dispatcher.utter_template("utter_able_to_finish", tracker)
return []
问题是文件大小打印为0,并在“完成”回调之前记录,我认为这是因为文件未完全下载。有没有一种方法不使用异步/等待来等待文件下载,然后再获取其实际大小//或在其他地方使用它?