slackapi/python-slack-sdk

What is 'Received a response in a non-JSON format' in chat.update

Nagisa1002 opened this issue · 3 comments

The error occurs in chat.update, but I can't find the cause.
Even if I enter the same text, it may not occur.

code:
The streaming output is reproduced on slack by rewriting the text output in token units from LLM using chat.update every 5 seconds.

temp_response = say('generating...', thread_ts=thread_ts)
    ch, ts = temp_response['channel'], temp_response['ts']
    last_update = -1
    for text in generator:
        if (time.time() - last_update) > 5.0 and text.strip():
            last_update = time.time()
            slack_bolt_app.client.chat_update(
                channel=ch, ts=ts, text=text)
            last_post_text = text

    if last_post_text != text:
        slack_bolt_app.client.chat_update(channel=ch, ts=ts, text=text)

error:

  File "/usr/local/jupyter/app/slack_chatinterface.py", line 47, in run_stream
    slack_bolt_app.client.chat_update(
  File "/usr/local/lib/python3.11/site-packages/slack_sdk/web/client.py", line 2686, in chat_update
    return self.api_call("chat.update", json=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/slack_sdk/web/base_client.py", line 155, in api_call
    return self._sync_send(api_url=api_url, req_args=req_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/slack_sdk/web/base_client.py", line 186, in _sync_send
    return self._urllib_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/slack_sdk/web/base_client.py", line 317, in _urllib_api_call
    ).validate()
      ^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/slack_sdk/web/slack_response.py", line 199, in validate
    raise e.SlackApiError(message=msg, response=self)
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://www.slack.com/api/chat.update)
The server responded with: {'ok': False, 'error': 'Received a response in a non-JSON format: '}

Hi @Nagisa1002, thanks for asking the question.

I guess the "text" argument you pass to the method may not be a string. If that's the case, your request to chat.update API could be invalid. I would recommend double-checking the "text" data provded by the "generator". If it's not a string, you need to build a string data before passing it. Also, enabling debug-level logging may help you out. You can add the following lines of code before the code you're investigating:

import logging
logging.basicConfig(level=logging.DEBUG)

I hope you will figure the cause out soon!

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.