Coder Social home page Coder Social logo

KeyError: 'ts' about response HOT 9 CLOSED

monzo avatar monzo commented on May 20, 2024
KeyError: 'ts'

from response.

Comments (9)

time-less-ness avatar time-less-ness commented on May 20, 2024 1

In my case, this was caused by Slack having too many channels. Ever since I added the cursor code, I never see this error/problem anymore.

from response.

danpalmer avatar danpalmer commented on May 20, 2024

I just got this as well. This might happen if the response from the Slack API is an error rather than a success (the ts identifies the message in a way, and no message was created). If you add a print(response), or print(response['error']) above that line then you should be able to see the error. In my case, the error was channel_not_found, as I had followed the setup instructions and used the #incidents channel, but not yet actually created the channel. I created the channel, and after restarting response it worked as expected.

from response.

pabsi avatar pabsi commented on May 20, 2024

I followed the README's instructions to the letter and I am hitting this error too:

response    |   File "/app/slack/models/headline_post.py", line 79, in update_in_slack
response    |     self.message_ts = response['ts']
response    | KeyError: 'ts'

Channel exists, and it is public. I added the bot to it too by "@" it. As an extra, "@" ing the bot for help (@incident_bot help) does not do anything. Logs don't show anything either. All URLs udated to use ngrok ones.

As suggested by @danpalmer I added print(response) to slack/models/headline_post.py and got the following:

response    | {'ok': False, 'error': 'channel_not_found', 'headers': {'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '60', 'Connection': 'keep-alive', 'Date': 'Fri, 14 Jun 2019 12:41:15 GMT', 'Server': 'Apache', 'X-Content-Type-Options': 'nosniff', 'X-Slack-Req-Id': 'xxxxxxxxxxxxxxx', 'X-OAuth-Scopes': 'identify,bot,commands,channels:history,channels:read,users:read,channels:write,chat:write:user,chat:write:bot', 'Expires': 'Mon, 26 Jul 1997 05:00:00 GMT', 'Cache-Control': 'private, no-cache, no-store, must-revalidate', 'Access-Control-Expose-Headers': 'x-slack-req-id', 'X-XSS-Protection': '0', 'X-Accepted-OAuth-Scopes': 'chat:write:bot', 'Vary': 'Accept-Encoding', 'Pragma': 'no-cache', 'Access-Control-Allow-Headers': 'slack-route, x-slack-version-ts', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Referrer-Policy': 'no-referrer', 'Content-Encoding': 'gzip', 'Access-Control-Allow-Origin': '*', 'X-Via': 'haproxy-www-0q2r', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 63d897654686e9908c8e03c9efa9c27c.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'LHR62-C2', 'X-Amz-Cf-Id': 'xxxxxxxxxxxxxxx=='}}

Key is 'error': 'channel_not_found'. Channel exists. I tried on two different channels even created a new one.

My setup:

  • Running locally (development)
  • Latest master as of today (14/06/2019)
  • My .env:
INCIDENT_CHANNEL_NAME="001-incident-tests"
INCIDENT_BOT_NAME="incident_bot"
PAGERDUTY_ENABLED="False"

Any suggestions

EDIT:
as per https://api.slack.com/methods/chat.postMessage :

channel_not_found : Value passed for channel was invalid

from response.

dsolsona avatar dsolsona commented on May 20, 2024

I'm currently having the same issue and in my case it seems to be due to having way too many channels in Slack.

In https://github.com/monzo/response/blob/master/response/settings/dev.py#L53-L56 the code tries to get the Slack channel ID by calling https://github.com/monzo/response/blob/master/response/settings/base.py#L191

My assumption is that this api call does not handle pagination properly, if you have more than 1000 channels in Slack the API call will return you a thousand and a cursor to get the next batch of channels. If get_channel_id doesn't find any channel then response will just set it to None and that pretty much breaks everything.

from response.

adamlphillips avatar adamlphillips commented on May 20, 2024

This may also happen if you don't have enough permissions. You may need an additional scope. If you see the scope that is needed in slack oAuth permissions you may need to update your SLACK_TOKEN environment variable with the latest token.

from response.

time-less-ness avatar time-less-ness commented on May 20, 2024

Any clues on this one?

I get the channel_not_found error, but:

INCIDENT_CHANNEL_NAME="incidents"

And I have an #incidents channel. We only have maybe a few hundred Slack channels (how would I know?). I'm going to try again now with a channel called 00-incidents and hopefully that will sort enough to the start (if the problem is too many channels).

UPDATE: Nope. I re-configured everything with INCIDENT_CHANNEL_NAME="00-incidents" and created the channel, and still get the same error.

from response.

time-less-ness avatar time-less-ness commented on May 20, 2024

For precision, the error is:

response    | Error: channel_not_found, Need: None

Is this a whole different issue than the KeyError: 'ts' issue that this is attached to? I also get that, but I feel like maybe the ts KeyError problem is a generic thing you get all the time, and the most common cause right now is the channel_not_found? Just a guess from reading the Issue, but I might be just hoping since that's my particular situation.

from response.

milesbxf avatar milesbxf commented on May 20, 2024

The above responses are correct - this generally happens because the Slack API returns slightly weird responses - if there's an error, we get a response like this:

{
  "ok": false,
  "error": "channel_not_found"
}

Previously, the code would only look for the ["ts"] key, and not find it in this response, causing that error.

We've done some refactoring recently to the Slack client (in #83 ) so that it now explicitly checks any response from the Slack API for {"ok": true} and raises an exception if that's not present, which should make debugging issues like this much easier 🙏

from response.

milesbxf avatar milesbxf commented on May 20, 2024

We've released 0.1.1 which includes better error handling for Slack - it should be much easier to debug instances of this in future. If there are specific bugs around Slack handling (like the Slack channel cursoring @philovivero mentioned), please raise a new issue and we'll take it from there ❤️

https://github.com/monzo/response/releases/tag/release-0.1.1

from response.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.