Python написание запросов в txt - РАСА - PullRequest
0 голосов
/ 04 января 2019

Я использую Python-запросы для получения HTTP API данных из стека Rasa. Это не проблема, когда я пытался в командной строке. Однако когда я реализовал его в сценарии python, он просто остановился, и сервер также перестал работать.

часть кода:

import os
import requests, json

    def submit(self, dispatcher, tracker, domain):

        agree_info = AgreeInfo()
        booking = agree_info.save(tracker.latest_message.get("text"))
        r = requests.get('http://localhost:5005/conversations/default/tracker')
        indexFile_senderid = open(str(tracker.latest_message.get("text")) + '.txt', 'w+', encoding='utf-8')
        indexFile_senderid.write('student ID: ' + tracker.latest_message.get("text") + str('\n\n'))
        indexFile_senderid.write(str(r.text) + str('\n\n'))
        indexFile_senderid.close()
        return[]

Результат txt файла должен выглядеть так:

student id
HTTP/1.1 200 OK
Vary: Accept
Content-Type: text/javascript

{
    "events": [
        {
            "event": "action",
            "name": "action_listen"
        },
        {
            "event": "user",
            "parse_data": {
                "entities": [],
                "intent": {
                    "confidence": 0.7561643619088745,
                    "name": "affirm"
                },
                "intent_ranking": [
                    ...
                ],
                "text": "hello there"
            },
            "text": "hello there"
        }
    ],
    "latest_message": {
        "entities": [],
        "intent": {
            "confidence": 0.7561643619088745,
            "name": "affirm"
        },
        "intent_ranking": [
            ...
        ],
        "text": "hello there"
    },
    "paused": false,
    "sender_id": "default",
    "slots": {
        "cuisine": null,
        "info": null,
        "location": null,
        "matches": null,
        "people": null,
        "price": null
    }
}
...