prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Mattermost Notification fails on latest release
  ##### ISSUE TYPE
   - Bug Report
  
  ##### SUMMARY
  Trying to send a (test) notification to a Mattermost Channel fails with
  ```
   mattermostinfo: Notification failed.
  Error sending notification mattermost: {"id":"api.webhook.incoming.error","message":"Could not decode the multipart payload of incoming webhook.","detailed_error":"","request_id":"<request ID>","status_code":400}
  ```
  ##### ENVIRONMENT
  * AWX version: 11.2.0
  * AWX install method: docker on linux
  * Ansible version:  2.9.7
  * Operating System: CentOS 7.8
  * Web Browser: Chrome,Chromium,Firefox
  * Mattermost Server Version: 5.22.1
  
  ##### STEPS TO REPRODUCE
  - Create an incomming webhook
  - Create a mattermost notification
  - Send a test notification
  
  
  ##### EXPECTED RESULTS
  Having a notification in the Channel
  
  
  ##### ACTUAL RESULTS
  
  Sending failed with above error message
  
  ##### ADDITIONAL INFORMATION
  
  The error message in the mattermost log shows
  ```
  {"level":"error","ts":1591342011.6592789,"caller":"mlog/log.go:175","msg":"Could not decode the multipart payload of incoming webhook.","path":"/
  hooks/<hook ID>","request_id":"<request ID>","ip_addr":"<IP Address>","user_id":"","method":"POST","err_where":"
  incomingWebhook","http_code":400,"err_details":"mime: no media type"}
  ```
  ---
  edit: some ID removed in the log sample, mattermost server version added
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `awx/main/notifications/mattermost_backend.py`
  Content:
  ```
  1 # Copyright (c) 2016 Ansible, Inc.
  2 # All Rights Reserved.
  3 
  4 import logging
  5 import requests
  6 import json
  7 
  8 from django.utils.encoding import smart_text
  9 from django.utils.translation import ugettext_lazy as _
  10 
  11 from awx.main.notifications.base import AWXBaseEmailBackend
  12 from awx.main.notifications.custom_notification_base import CustomNotificationBase
  13 
  14 logger = logging.getLogger('awx.main.notifications.mattermost_backend')
  15 
  16 
  17 class MattermostBackend(AWXBaseEmailBackend, CustomNotificationBase):
  18 
  19     init_parameters = {"mattermost_url": {"label": "Target URL", "type": "string"},
  20                        "mattermost_no_verify_ssl": {"label": "Verify SSL", "type": "bool"}}
  21     recipient_parameter = "mattermost_url"
  22     sender_parameter = None
  23 
  24     def __init__(self, mattermost_no_verify_ssl=False, mattermost_channel=None, mattermost_username=None,
  25                  mattermost_icon_url=None, fail_silently=False, **kwargs):
  26         super(MattermostBackend, self).__init__(fail_silently=fail_silently)
  27         self.mattermost_channel = mattermost_channel
  28         self.mattermost_username = mattermost_username
  29         self.mattermost_icon_url = mattermost_icon_url
  30         self.mattermost_no_verify_ssl = mattermost_no_verify_ssl
  31 
  32     def format_body(self, body):
  33         return body
  34 
  35     def send_messages(self, messages):
  36         sent_messages = 0
  37         for m in messages:
  38             payload = {}
  39             for opt, optval in {'mattermost_icon_url':'icon_url',
  40                                 'mattermost_channel': 'channel', 'mattermost_username': 'username'}.items():
  41                 optvalue = getattr(self, opt)
  42                 if optvalue is not None:
  43                     payload[optval] = optvalue.strip()
  44 
  45             payload['text'] = m.subject
  46 
  47             r = requests.post("{}".format(m.recipients()[0]),
  48                               data=json.dumps(payload), verify=(not self.mattermost_no_verify_ssl))
  49             if r.status_code >= 400:
  50                 logger.error(smart_text(_("Error sending notification mattermost: {}").format(r.text)))
  51                 if not self.fail_silently:
  52                     raise Exception(smart_text(_("Error sending notification mattermost: {}").format(r.text)))
  53             sent_messages += 1
  54         return sent_messages
  55
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/awx/main/notifications/mattermost_backend.py b/awx/main/notifications/mattermost_backend.py
  --- a/awx/main/notifications/mattermost_backend.py
  +++ b/awx/main/notifications/mattermost_backend.py
  @@ -3,7 +3,6 @@
   
   import logging
   import requests
  -import json
   
   from django.utils.encoding import smart_text
   from django.utils.translation import ugettext_lazy as _
  @@ -45,7 +44,7 @@
               payload['text'] = m.subject
   
               r = requests.post("{}".format(m.recipients()[0]),
  -                              data=json.dumps(payload), verify=(not self.mattermost_no_verify_ssl))
  +                              json=payload, verify=(not self.mattermost_no_verify_ssl))
               if r.status_code >= 400:
                   logger.error(smart_text(_("Error sending notification mattermost: {}").format(r.text)))
                   if not self.fail_silently:
  
verification_info: {"golden_diff": "diff --git a/awx/main/notifications/mattermost_backend.py b/awx/main/notifications/mattermost_backend.py\n--- a/awx/main/notifications/mattermost_backend.py\n+++ b/awx/main/notifications/mattermost_backend.py\n@@ -3,7 +3,6 @@\n \n import logging\n import requests\n-import json\n \n from django.utils.encoding import smart_text\n from django.utils.translation import ugettext_lazy as _\n@@ -45,7 +44,7 @@\n             payload['text'] = m.subject\n \n             r = requests.post(\"{}\".format(m.recipients()[0]),\n-                              data=json.dumps(payload), verify=(not self.mattermost_no_verify_ssl))\n+                              json=payload, verify=(not self.mattermost_no_verify_ssl))\n             if r.status_code >= 400:\n                 logger.error(smart_text(_(\"Error sending notification mattermost: {}\").format(r.text)))\n                 if not self.fail_silently:\n", "issue": "Mattermost Notification fails on latest release\n##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### SUMMARY\r\nTrying to send a (test) notification to a Mattermost Channel fails with\r\n```\r\n mattermostinfo: Notification failed.\r\nError sending notification mattermost: {\"id\":\"api.webhook.incoming.error\",\"message\":\"Could not decode the multipart payload of incoming webhook.\",\"detailed_error\":\"\",\"request_id\":\"<request ID>\",\"status_code\":400}\r\n```\r\n##### ENVIRONMENT\r\n* AWX version: 11.2.0\r\n* AWX install method: docker on linux\r\n* Ansible version:  2.9.7\r\n* Operating System: CentOS 7.8\r\n* Web Browser: Chrome,Chromium,Firefox\r\n* Mattermost Server Version: 5.22.1\r\n\r\n##### STEPS TO REPRODUCE\r\n- Create an incomming webhook\r\n- Create a mattermost notification\r\n- Send a test notification\r\n\r\n\r\n##### EXPECTED RESULTS\r\nHaving a notification in the Channel\r\n\r\n\r\n##### ACTUAL RESULTS\r\n\r\nSending failed with above error message\r\n\r\n##### ADDITIONAL INFORMATION\r\n\r\nThe error message in the mattermost log shows\r\n```\r\n{\"level\":\"error\",\"ts\":1591342011.6592789,\"caller\":\"mlog/log.go:175\",\"msg\":\"Could not decode the multipart payload of incoming webhook.\",\"path\":\"/\r\nhooks/<hook ID>\",\"request_id\":\"<request ID>\",\"ip_addr\":\"<IP Address>\",\"user_id\":\"\",\"method\":\"POST\",\"err_where\":\"\r\nincomingWebhook\",\"http_code\":400,\"err_details\":\"mime: no media type\"}\r\n```\r\n---\r\nedit: some ID removed in the log sample, mattermost server version added\n", "before_files": [{"content": "# Copyright (c) 2016 Ansible, Inc.\n# All Rights Reserved.\n\nimport logging\nimport requests\nimport json\n\nfrom django.utils.encoding import smart_text\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom awx.main.notifications.base import AWXBaseEmailBackend\nfrom awx.main.notifications.custom_notification_base import CustomNotificationBase\n\nlogger = logging.getLogger('awx.main.notifications.mattermost_backend')\n\n\nclass MattermostBackend(AWXBaseEmailBackend, CustomNotificationBase):\n\n    init_parameters = {\"mattermost_url\": {\"label\": \"Target URL\", \"type\": \"string\"},\n                       \"mattermost_no_verify_ssl\": {\"label\": \"Verify SSL\", \"type\": \"bool\"}}\n    recipient_parameter = \"mattermost_url\"\n    sender_parameter = None\n\n    def __init__(self, mattermost_no_verify_ssl=False, mattermost_channel=None, mattermost_username=None,\n                 mattermost_icon_url=None, fail_silently=False, **kwargs):\n        super(MattermostBackend, self).__init__(fail_silently=fail_silently)\n        self.mattermost_channel = mattermost_channel\n        self.mattermost_username = mattermost_username\n        self.mattermost_icon_url = mattermost_icon_url\n        self.mattermost_no_verify_ssl = mattermost_no_verify_ssl\n\n    def format_body(self, body):\n        return body\n\n    def send_messages(self, messages):\n        sent_messages = 0\n        for m in messages:\n            payload = {}\n            for opt, optval in {'mattermost_icon_url':'icon_url',\n                                'mattermost_channel': 'channel', 'mattermost_username': 'username'}.items():\n                optvalue = getattr(self, opt)\n                if optvalue is not None:\n                    payload[optval] = optvalue.strip()\n\n            payload['text'] = m.subject\n\n            r = requests.post(\"{}\".format(m.recipients()[0]),\n                              data=json.dumps(payload), verify=(not self.mattermost_no_verify_ssl))\n            if r.status_code >= 400:\n                logger.error(smart_text(_(\"Error sending notification mattermost: {}\").format(r.text)))\n                if not self.fail_silently:\n                    raise Exception(smart_text(_(\"Error sending notification mattermost: {}\").format(r.text)))\n            sent_messages += 1\n        return sent_messages\n", "path": "awx/main/notifications/mattermost_backend.py"}], "after_files": [{"content": "# Copyright (c) 2016 Ansible, Inc.\n# All Rights Reserved.\n\nimport logging\nimport requests\n\nfrom django.utils.encoding import smart_text\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom awx.main.notifications.base import AWXBaseEmailBackend\nfrom awx.main.notifications.custom_notification_base import CustomNotificationBase\n\nlogger = logging.getLogger('awx.main.notifications.mattermost_backend')\n\n\nclass MattermostBackend(AWXBaseEmailBackend, CustomNotificationBase):\n\n    init_parameters = {\"mattermost_url\": {\"label\": \"Target URL\", \"type\": \"string\"},\n                       \"mattermost_no_verify_ssl\": {\"label\": \"Verify SSL\", \"type\": \"bool\"}}\n    recipient_parameter = \"mattermost_url\"\n    sender_parameter = None\n\n    def __init__(self, mattermost_no_verify_ssl=False, mattermost_channel=None, mattermost_username=None,\n                 mattermost_icon_url=None, fail_silently=False, **kwargs):\n        super(MattermostBackend, self).__init__(fail_silently=fail_silently)\n        self.mattermost_channel = mattermost_channel\n        self.mattermost_username = mattermost_username\n        self.mattermost_icon_url = mattermost_icon_url\n        self.mattermost_no_verify_ssl = mattermost_no_verify_ssl\n\n    def format_body(self, body):\n        return body\n\n    def send_messages(self, messages):\n        sent_messages = 0\n        for m in messages:\n            payload = {}\n            for opt, optval in {'mattermost_icon_url':'icon_url',\n                                'mattermost_channel': 'channel', 'mattermost_username': 'username'}.items():\n                optvalue = getattr(self, opt)\n                if optvalue is not None:\n                    payload[optval] = optvalue.strip()\n\n            payload['text'] = m.subject\n\n            r = requests.post(\"{}\".format(m.recipients()[0]),\n                              json=payload, verify=(not self.mattermost_no_verify_ssl))\n            if r.status_code >= 400:\n                logger.error(smart_text(_(\"Error sending notification mattermost: {}\").format(r.text)))\n                if not self.fail_silently:\n                    raise Exception(smart_text(_(\"Error sending notification mattermost: {}\").format(r.text)))\n            sent_messages += 1\n        return sent_messages\n", "path": "awx/main/notifications/mattermost_backend.py"}]}