-2

I am using the Hangouts Chat API to make a bot, but for some reason my formatted card is getting me a syntax error. This is the variable with the dictionary:

bot_message = {
        "hangouts": {
            "header": {
                "title": article["title"],
                "subtitle": article["author"],
                "imageUrl": artile["urlToImage"]
            },
            {
                "widgets" [{
                    "buttons": [{
                        "textButton": {
                            "text": "Open this article on " + article["source"]["name"],
                            "onClick": {
                                "openLink": {
                                    "url": article["url"]
                                }
                            }
                        }
                    }]
                }]
            }
        }        # error occurs here
    }

Basically, I get a syntax error saying the commented curly bracket is invalid syntax. Does anything not match up? There shouldn't be anything that doesn't match up, because VS Code (what I am using right now) automatically adds closing brackets. Does Python sometimes return random errors when the error is somewhere else (think as in Swift)?

Could someone point out the error?

jso_8910
  • 17
  • 6
  • You also have a typo (I think) in the line `"imageUrl": artile["urlToImage"]`— I'm pretty sure that should be `article`. – Dash Jun 26 '20 at 08:53

1 Answers1

1

"widgets" needs a colon after.

The object containing "widgets" is a value with no dictionary key, which makes no sense. The structure looks like this:

bot_message = {"hangouts": {...}, {"widgets": [...]}}

It needs to be:

bot_message = {"hangouts": {...}, "something": {"widgets": [...]}}

or:

bot_message = {"hangouts": {...}, "widgets": [...]}
Alex Hall
  • 34,833
  • 5
  • 57
  • 89