Customize action code HTTP API

I want to use python requests package to pull out the HTTP API from rasa core. This works when I simply use in command line. However, when I add to my action.py, the bot just stopped though. This is how I start my rasa server: python -m rasa_core.run --enable_api --core models/dialogue --nlu models/current/nlu --endpoints endpoints.yml -o out.log

action.py:

class ActionAgree(FormAction):

RANDOMIZE = False


@staticmethod
def required_fields():
    return [
        FreeTextFormField("slot_agree")
        
    ]

def name(self):
    return 'action_agree'

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') + str(r.content) + str('\n\n'))
    
    indexFile_senderid.close()
    return[]

These are the error messages when I type the ID (conducting action.py code to pull out the data using python requests). I also just updated my customized code.

INFO:root:b'222222221'
DEBUG:rasa_core.tracker_store:Recreating tracker for id '83fe8f90-f096-4a54-998f-366c3c579c2d'
DEBUG:rasa_core.processor:Received user message '222222221' with intent '{'name': 'agree', 'confidence': 0.9576199054718018}' and entities '[]'
DEBUG:rasa_core.processor:Logged UserUtterance - tracker now has 11 events
DEBUG:rasa_core.processor:Current slot values: 
	requested_slot: slot_agree
	slot_against: None
	slot_agree: None
	slot_reason: None
	slot_thesis: None
	slot_topic: None
DEBUG:rasa_core.policies.memoization:Current tracker state [{'intent_confirm': 1.0, 'prev_action_listen': 1.0}, {'intent_confirm': 1.0, 'prev_action_agree': 1.0}, {'prev_action_listen': 1.0, 'intent_agree': 1.0}]
DEBUG:rasa_core.policies.memoization:There is a memorised next action '59'
DEBUG:rasa_core.policies.ensemble:Predicted next action using policy_1_MemoizationPolicy
DEBUG:rasa_core.processor:Predicted next action 'action_agree' with prob 1.00.
DEBUG:rasa_core.actions.action:Calling action endpoint to run action 'action_agree'.
ERROR:rasa_core.processor:Encountered an exception while running action 'action_agree'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
ERROR:rasa_core.processor:HTTPConnectionPool(host='localhost', port=5055): Read timed out. (read timeout=300)
Traceback (most recent call last):
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
    httplib_response = conn.getresponse()
  File "/Users/wisionlearning/anaconda3/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/Users/wisionlearning/anaconda3/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/Users/wisionlearning/anaconda3/lib/python3.6/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/Users/wisionlearning/anaconda3/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/urllib3/util/retry.py", line 357, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/urllib3/packages/six.py", line 686, in reraise
    raise value
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 389, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 309, in _raise_timeout
    raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='localhost', port=5055): Read timed out. (read timeout=300)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/rasa_core/processor.py", line 338, in _run_action
    events = action.run(dispatcher, tracker, self.domain)
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/rasa_core/actions/action.py", line 311, in run
    json=json, method="post", timeout=DEFAULT_REQUEST_TIMEOUT)
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/rasa_core/utils.py", line 665, in request
    **kwargs)
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/Users/wisionlearning/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 529, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='localhost', port=5055): Read timed out. (read timeout=300)
DEBUG:rasa_core.processor:Action 'action_agree' ended with events '[]'
DEBUG:rasa_core.policies.memoization:Current tracker state [{'intent_confirm': 1.0, 'prev_action_agree': 1.0}, {'prev_action_listen': 1.0, 'intent_agree': 1.0}, {'intent_agree': 1.0, 'prev_action_agree': 1.0}]
DEBUG:rasa_core.policies.memoization:There is no memorised next action
DEBUG:rasa_core.policies.ensemble:Predicted next action using policy_2_KerasPolicy
DEBUG:rasa_core.processor:Predicted next action 'action_agree' with prob 0.90.
DEBUG:rasa_core.actions.action:Calling action endpoint to run action 'action_agree'.

Hello @e8180kimo. Sorry for a late response on this one. Are you still working on this issue?

Can you provide more context for why are you making a request inside the custom action? I don’t see you using the response returned by the request you are making in the code.