rveachkc / pymsteams

Format messages and post to Microsoft Teams.
https://pypi.org/project/pymsteams/
Apache License 2.0
422 stars 78 forks source link

Suppressed error when 403 is returned #50

Closed ghost closed 5 years ago

ghost commented 5 years ago

Whenever posting to a webhook results in a 403 Forbidden, this information is never presented and no TeamsWebhookException is thrown.

I've had a few projects running w/ pymsteams for a while, when suddenly one stopped working today. Nothing seemed to be wrong when running the script, so I started manually POSTing to the connector URL only to find that I was getting a 403 back.

rveachkc commented 5 years ago

Interesting, it should raise the exception based on this code, since requests.codes.ok will only match a 200.

        if r.status_code == requests.codes.ok:
            return True
        else:
            raise TeamsWebhookException(r.text)

I'll have to develop a test for this to see if I can reproduce.

ghost commented 5 years ago

I saw that too, but the error was still being suppressed. I've gone ahead and verified that I am on the latest available on pip, and that the issue is still there. If need be, I can provide you with a webhook URL that is giving me the 403.

rveachkc commented 5 years ago

Time got away from me again, and I just now got around to testing this out. I added a test for an http 403 error code, and it does throw the TeamsWebhookException for me. Source in test_webhook.py:

def test_http_403():
    with pytest.raises(pymsteams.TeamsWebhookException):
        myTeamsMessage = pymsteams.connectorcard("http://httpstat.us/403")
        myTeamsMessage.text("This is a simple text message.")
        myTeamsMessage.title("Simple Message Title")
        myTeamsMessage.send()

If I edit the test to keep it from expecting the exception, it fails, as it should.

This uses the httpstat.us webservice to provide an http 403. If you are still having trouble with the webhook, I can take a look, but I will need the url to do so.

ghost commented 5 years ago

In the time since I opened this issue, I resolved the cause of the 403 on MS's side (migration to new admin dashboard broke permissions) so I probably won't have a "bad" link to provide for a while yet. if I do encounter it again, I'll open a new issue and include the URL I am using.

Thank you very much for all of your assistance!