flask-sendgrid icon indicating copy to clipboard operation
flask-sendgrid copied to clipboard

Flask-Sendgrid double emails after first request

Open Seluj78 opened this issue 6 years ago • 2 comments

I've added a print here to see the request you send to sendgrid

        content = Content("text/html", html) if html else Content("text/plain", text)
        self.add_content(content)

        import json
        print(json.dumps(self.get(), sort_keys=True, indent=4))

        return self.client.mail.send.post(request_body=self.get())

Here's what I get from the start of the server, first request to send a mail then the second one

FLASK_APP = application.py
FLASK_ENV = staging
FLASK_DEBUG = 1
In folder /Users/seluj78/Projects/VisionaeAPI
/Users/seluj78/Projects/VisionaeAPI/venv/bin/python -m flask run
 * Serving Flask app "application.py" (lazy loading)
 * Environment: staging
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with fsevents reloader
 * Debugger is active!
 * Debugger PIN: 800-184-622
In route: data['email'] = [email protected]
In send_password_reset_email : email = [email protected]
In sendmail : email = [email protected]
{
    "content": [
        {
            "type": "text/html",
            "value": "<!DOCTYPE html>\n<html>\n<head>\n\n  <meta charset=\"utf-8\">\n  <meta http-equiv=\"x-ua-compatible\" content=\"ie=edge\">\n  <title>Password Reset</title>\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <style type=\"text/css\">\n  /**\n   * Google webfonts. Recommended to include the .woff version for cross-client compatibility.\n   */\n  @media screen {\n    @font-face {\n      font-family: 'Source Sans Pro';\n      font-style: normal;\n      font-weight: 400;\n      src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v10/ODelI1aHBYDBqgeIAH2zlBM0YzuT7MdOe03otPbuUS0.woff) format('woff');\n    }\n\n    @font-face {\n      font-family: 'Source Sans Pro';\n      font-style: normal;\n      font-weight: 700;\n      src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url(https://fonts.gstatic.com/s/sourcesanspro/v10/toadOcfmlt9b38dHJxOBGFkQc6VGVFSmCnC_l7QZG60.woff) format('woff');\n    }\n  }\n\n  /**\n   * Avoid browser level font resizing.\n   * 1. Windows Mobile\n   * 2. iOS / OSX\n   */\n  body,\n  table,\n  td,\n  a {\n    -ms-text-size-adjust: 100%; /* 1 */\n    -webkit-text-size-adjust: 100%; /* 2 */\n  }\n\n  /**\n   * Remove extra space added to tables and cells in Outlook.\n   */\n  table,\n  td {\n    mso-table-rspace: 0pt;\n    mso-table-lspace: 0pt;\n  }\n\n  /**\n   * Better fluid images in Internet Explorer.\n   */\n  img {\n    -ms-interpolation-mode: bicubic;\n  }\n\n  /**\n   * Remove blue links for iOS devices.\n   */\n  a[x-apple-data-detectors] {\n    font-family: inherit !important;\n    font-size: inherit !important;\n    font-weight: inherit !important;\n    line-height: inherit !important;\n    color: inherit !important;\n    text-decoration: none !important;\n  }\n\n  /**\n   * Fix centering issues in Android 4.4.\n   */\n  div[style*=\"margin: 16px 0;\"] {\n    margin: 0 !important;\n  }\n\n  body {\n    width: 100% !important;\n    height: 100% !important;\n    padding: 0 !important;\n    margin: 0 !important;\n  }\n\n  /**\n   * Collapse table borders to avoid space between cells.\n   */\n  table {\n    border-collapse: collapse !important;\n  }\n\n  a {\n    color: #1a82e2;\n  }\n\n  img {\n    height: auto;\n    line-height: 100%;\n    text-decoration: none;\n    border: 0;\n    outline: none;\n  }\n  </style>\n\n</head>\n<body style=\"background-color: #e9ecef;\">\n\n  <!-- start preheader -->\n  <div class=\"preheader\" style=\"display: none; max-width: 0; max-height: 0; overflow: hidden; font-size: 1px; line-height: 1px; color: #fff; opacity: 0;\">\n    Reset your password for Visionae\n  </div>\n  <!-- end preheader -->\n\n  <!-- start body -->\n  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n\n    <!-- start logo -->\n    <tr>\n      <td align=\"center\" bgcolor=\"#e9ecef\">\n        <!--[if (gte mso 9)|(IE)]>\n        <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n        <tr>\n        <td align=\"center\" valign=\"top\" width=\"600\">\n        <![endif]-->\n        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 600px;\">\n          <tr>\n            <td align=\"center\" valign=\"top\" style=\"padding: 36px 24px;\">\n              <a href=\"https://visionae.fr\" target=\"_blank\" rel=\"noopener\" style=\"display: inline-block;\">\n                <img src=\"https://backoffice.visionae.fr/static/img/visionae-logo.png\" alt=\"Logo\" border=\"0\" width=\"216px\" style=\"display: block; width: 216px; max-width: 216px; min-width: 48px;\">\n              </a>\n            </td>\n          </tr>\n        </table>\n        <!--[if (gte mso 9)|(IE)]>\n        </td>\n        </tr>\n        </table>\n        <![endif]-->\n      </td>\n    </tr>\n    <!-- end logo -->\n\n    <!-- start hero -->\n    <tr>\n      <td align=\"center\" bgcolor=\"#e9ecef\">\n        <!--[if (gte mso 9)|(IE)]>\n        <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n        <tr>\n        <td align=\"center\" valign=\"top\" width=\"600\">\n        <![endif]-->\n        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 600px;\">\n          <tr>\n            <td align=\"left\" bgcolor=\"#ffffff\" style=\"padding: 36px 24px 0; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; border-top: 3px solid #d4dadf;\">\n              <h1 style=\"text-align: center; margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -1px; line-height: 48px;\">Reset Your Password</h1>\n            </td>\n          </tr>\n        </table>\n        <!--[if (gte mso 9)|(IE)]>\n        </td>\n        </tr>\n        </table>\n        <![endif]-->\n      </td>\n    </tr>\n    <!-- end hero -->\n\n    <!-- start copy block -->\n    <tr>\n      <td align=\"center\" bgcolor=\"#e9ecef\">\n        <!--[if (gte mso 9)|(IE)]>\n        <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n        <tr>\n        <td align=\"center\" valign=\"top\" width=\"600\">\n        <![endif]-->\n        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 600px;\">\n\n          <!-- start copy -->\n          <tr>\n            <td align=\"left\" bgcolor=\"#ffffff\" style=\"padding: 24px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;\">\n              <p style=\"margin: 0;\">Press the button below to reset your account password. If you didn't request a new password, you can safely delete this email.</p>\n              <p style=\"margin: 0;\"><i>This link will no longer be available in 30 minutes.</i></p>\n            </td>\n          </tr>\n          <!-- end copy -->\n\n          <!-- start button -->\n          <tr>\n            <td align=\"left\" bgcolor=\"#ffffff\">\n              <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n                <tr>\n                  <td align=\"center\" bgcolor=\"#ffffff\" style=\"padding: 12px;\">\n                    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n                      <tr>\n                        <td align=\"center\" bgcolor=\"#1a82e2\" style=\"border-radius: 6px;\">\n                          <a href=\"http://127.0.0.1:2000/reset_password/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZXNldF9wYXNzd29yZCI6MywiZXhwIjoxNTc0NjcwOTY4LjM3OTA0N30.tK1dGyZ14al2-v_I6EFTYqBZHtdesGgy4ugH0D5vnw0\" target=\"_blank\" rel=\"noopener\" style=\"display: inline-block; padding: 16px 36px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; color: #ffffff; text-decoration: none; border-radius: 6px;\">Reset your password</a>\n                        </td>\n                      </tr>\n                    </table>\n                  </td>\n                </tr>\n              </table>\n            </td>\n          </tr>\n          <!-- end button -->\n\n\n\n\n\n\n\n\n\n\n        </table>\n        <!--[if (gte mso 9)|(IE)]>\n        </td>\n        </tr>\n        </table>\n        <![endif]-->\n      </td>\n    </tr>\n    <!-- end copy block -->\n\n  </table>\n  <!-- end body -->\n\n</body>\n</html>"
        }
    ],
    "from": {
        "email": "[email protected]"
    },
    "personalizations": [
        {
            "to": [
                {
                    "email": "[email protected]"
                }
            ]
        }
    ],
    "reply_to": {
        "email": "[email protected]"
    },
    "subject": "Password reset for Visionae"
}
127.0.0.1 - - [25/Nov/2019 09:06:08] "POST /v1/auth/user/forgot_password HTTP/1.1" 200 -

Here the first request was successful Now the second one

In route: data['email'] = [email protected]
In send_password_reset_email : email = [email protected]
In sendmail : email = [email protected]
{
    "content": [
        {
            "type": "text/html",
            "value": "<!DOCTYPE html>\n<html>\n<head>\n\n  <meta charset=\"utf-8\">\n  <meta http-equiv=\"x-ua-compatible\" content=\"ie=edge\">\n  <title>Password Reset</title>\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <style type=\"text/css\">\n  /**\n   * Google webfonts. Recommended to include the .woff version for cross-client compatibility.\n   */\n  @media screen {\n    @font-face {\n      font-family: 'Source Sans Pro';\n      font-style: normal;\n      font-weight: 400;\n      src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v10/ODelI1aHBYDBqgeIAH2zlBM0YzuT7MdOe03otPbuUS0.woff) format('woff');\n    }\n\n    @font-face {\n      font-family: 'Source Sans Pro';\n      font-style: normal;\n      font-weight: 700;\n      src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url(https://fonts.gstatic.com/s/sourcesanspro/v10/toadOcfmlt9b38dHJxOBGFkQc6VGVFSmCnC_l7QZG60.woff) format('woff');\n    }\n  }\n\n  /**\n   * Avoid browser level font resizing.\n   * 1. Windows Mobile\n   * 2. iOS / OSX\n   */\n  body,\n  table,\n  td,\n  a {\n    -ms-text-size-adjust: 100%; /* 1 */\n    -webkit-text-size-adjust: 100%; /* 2 */\n  }\n\n  /**\n   * Remove extra space added to tables and cells in Outlook.\n   */\n  table,\n  td {\n    mso-table-rspace: 0pt;\n    mso-table-lspace: 0pt;\n  }\n\n  /**\n   * Better fluid images in Internet Explorer.\n   */\n  img {\n    -ms-interpolation-mode: bicubic;\n  }\n\n  /**\n   * Remove blue links for iOS devices.\n   */\n  a[x-apple-data-detectors] {\n    font-family: inherit !important;\n    font-size: inherit !important;\n    font-weight: inherit !important;\n    line-height: inherit !important;\n    color: inherit !important;\n    text-decoration: none !important;\n  }\n\n  /**\n   * Fix centering issues in Android 4.4.\n   */\n  div[style*=\"margin: 16px 0;\"] {\n    margin: 0 !important;\n  }\n\n  body {\n    width: 100% !important;\n    height: 100% !important;\n    padding: 0 !important;\n    margin: 0 !important;\n  }\n\n  /**\n   * Collapse table borders to avoid space between cells.\n   */\n  table {\n    border-collapse: collapse !important;\n  }\n\n  a {\n    color: #1a82e2;\n  }\n\n  img {\n    height: auto;\n    line-height: 100%;\n    text-decoration: none;\n    border: 0;\n    outline: none;\n  }\n  </style>\n\n</head>\n<body style=\"background-color: #e9ecef;\">\n\n  <!-- start preheader -->\n  <div class=\"preheader\" style=\"display: none; max-width: 0; max-height: 0; overflow: hidden; font-size: 1px; line-height: 1px; color: #fff; opacity: 0;\">\n    Reset your password for Visionae\n  </div>\n  <!-- end preheader -->\n\n  <!-- start body -->\n  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n\n    <!-- start logo -->\n    <tr>\n      <td align=\"center\" bgcolor=\"#e9ecef\">\n        <!--[if (gte mso 9)|(IE)]>\n        <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n        <tr>\n        <td align=\"center\" valign=\"top\" width=\"600\">\n        <![endif]-->\n        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 600px;\">\n          <tr>\n            <td align=\"center\" valign=\"top\" style=\"padding: 36px 24px;\">\n              <a href=\"https://visionae.fr\" target=\"_blank\" rel=\"noopener\" style=\"display: inline-block;\">\n                <img src=\"https://backoffice.visionae.fr/static/img/visionae-logo.png\" alt=\"Logo\" border=\"0\" width=\"216px\" style=\"display: block; width: 216px; max-width: 216px; min-width: 48px;\">\n              </a>\n            </td>\n          </tr>\n        </table>\n        <!--[if (gte mso 9)|(IE)]>\n        </td>\n        </tr>\n        </table>\n        <![endif]-->\n      </td>\n    </tr>\n    <!-- end logo -->\n\n    <!-- start hero -->\n    <tr>\n      <td align=\"center\" bgcolor=\"#e9ecef\">\n        <!--[if (gte mso 9)|(IE)]>\n        <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n        <tr>\n        <td align=\"center\" valign=\"top\" width=\"600\">\n        <![endif]-->\n        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 600px;\">\n          <tr>\n            <td align=\"left\" bgcolor=\"#ffffff\" style=\"padding: 36px 24px 0; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; border-top: 3px solid #d4dadf;\">\n              <h1 style=\"text-align: center; margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -1px; line-height: 48px;\">Reset Your Password</h1>\n            </td>\n          </tr>\n        </table>\n        <!--[if (gte mso 9)|(IE)]>\n        </td>\n        </tr>\n        </table>\n        <![endif]-->\n      </td>\n    </tr>\n    <!-- end hero -->\n\n    <!-- start copy block -->\n    <tr>\n      <td align=\"center\" bgcolor=\"#e9ecef\">\n        <!--[if (gte mso 9)|(IE)]>\n        <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n        <tr>\n        <td align=\"center\" valign=\"top\" width=\"600\">\n        <![endif]-->\n        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 600px;\">\n\n          <!-- start copy -->\n          <tr>\n            <td align=\"left\" bgcolor=\"#ffffff\" style=\"padding: 24px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;\">\n              <p style=\"margin: 0;\">Press the button below to reset your account password. If you didn't request a new password, you can safely delete this email.</p>\n              <p style=\"margin: 0;\"><i>This link will no longer be available in 30 minutes.</i></p>\n            </td>\n          </tr>\n          <!-- end copy -->\n\n          <!-- start button -->\n          <tr>\n            <td align=\"left\" bgcolor=\"#ffffff\">\n              <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n                <tr>\n                  <td align=\"center\" bgcolor=\"#ffffff\" style=\"padding: 12px;\">\n                    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n                      <tr>\n                        <td align=\"center\" bgcolor=\"#1a82e2\" style=\"border-radius: 6px;\">\n                          <a href=\"http://127.0.0.1:2000/reset_password/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZXNldF9wYXNzd29yZCI6MywiZXhwIjoxNTc0NjcwOTY4LjM3OTA0N30.tK1dGyZ14al2-v_I6EFTYqBZHtdesGgy4ugH0D5vnw0\" target=\"_blank\" rel=\"noopener\" style=\"display: inline-block; padding: 16px 36px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; color: #ffffff; text-decoration: none; border-radius: 6px;\">Reset your password</a>\n                        </td>\n                      </tr>\n                    </table>\n                  </td>\n                </tr>\n              </table>\n            </td>\n          </tr>\n          <!-- end button -->\n\n\n\n\n\n\n\n\n\n\n        </table>\n        <!--[if (gte mso 9)|(IE)]>\n        </td>\n        </tr>\n        </table>\n        <![endif]-->\n      </td>\n    </tr>\n    <!-- end copy block -->\n\n  </table>\n  <!-- end body -->\n\n</body>\n</html>"
        },
        {
            "type": "text/html",
            "value": "<!DOCTYPE html>\n<html>\n<head>\n\n  <meta charset=\"utf-8\">\n  <meta http-equiv=\"x-ua-compatible\" content=\"ie=edge\">\n  <title>Password Reset</title>\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <style type=\"text/css\">\n  /**\n   * Google webfonts. Recommended to include the .woff version for cross-client compatibility.\n   */\n  @media screen {\n    @font-face {\n      font-family: 'Source Sans Pro';\n      font-style: normal;\n      font-weight: 400;\n      src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v10/ODelI1aHBYDBqgeIAH2zlBM0YzuT7MdOe03otPbuUS0.woff) format('woff');\n    }\n\n    @font-face {\n      font-family: 'Source Sans Pro';\n      font-style: normal;\n      font-weight: 700;\n      src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url(https://fonts.gstatic.com/s/sourcesanspro/v10/toadOcfmlt9b38dHJxOBGFkQc6VGVFSmCnC_l7QZG60.woff) format('woff');\n    }\n  }\n\n  /**\n   * Avoid browser level font resizing.\n   * 1. Windows Mobile\n   * 2. iOS / OSX\n   */\n  body,\n  table,\n  td,\n  a {\n    -ms-text-size-adjust: 100%; /* 1 */\n    -webkit-text-size-adjust: 100%; /* 2 */\n  }\n\n  /**\n   * Remove extra space added to tables and cells in Outlook.\n   */\n  table,\n  td {\n    mso-table-rspace: 0pt;\n    mso-table-lspace: 0pt;\n  }\n\n  /**\n   * Better fluid images in Internet Explorer.\n   */\n  img {\n    -ms-interpolation-mode: bicubic;\n  }\n\n  /**\n   * Remove blue links for iOS devices.\n   */\n  a[x-apple-data-detectors] {\n    font-family: inherit !important;\n    font-size: inherit !important;\n    font-weight: inherit !important;\n    line-height: inherit !important;\n    color: inherit !important;\n    text-decoration: none !important;\n  }\n\n  /**\n   * Fix centering issues in Android 4.4.\n   */\n  div[style*=\"margin: 16px 0;\"] {\n    margin: 0 !important;\n  }\n\n  body {\n    width: 100% !important;\n    height: 100% !important;\n    padding: 0 !important;\n    margin: 0 !important;\n  }\n\n  /**\n   * Collapse table borders to avoid space between cells.\n   */\n  table {\n    border-collapse: collapse !important;\n  }\n\n  a {\n    color: #1a82e2;\n  }\n\n  img {\n    height: auto;\n    line-height: 100%;\n    text-decoration: none;\n    border: 0;\n    outline: none;\n  }\n  </style>\n\n</head>\n<body style=\"background-color: #e9ecef;\">\n\n  <!-- start preheader -->\n  <div class=\"preheader\" style=\"display: none; max-width: 0; max-height: 0; overflow: hidden; font-size: 1px; line-height: 1px; color: #fff; opacity: 0;\">\n    Reset your password for Visionae\n  </div>\n  <!-- end preheader -->\n\n  <!-- start body -->\n  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n\n    <!-- start logo -->\n    <tr>\n      <td align=\"center\" bgcolor=\"#e9ecef\">\n        <!--[if (gte mso 9)|(IE)]>\n        <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n        <tr>\n        <td align=\"center\" valign=\"top\" width=\"600\">\n        <![endif]-->\n        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 600px;\">\n          <tr>\n            <td align=\"center\" valign=\"top\" style=\"padding: 36px 24px;\">\n              <a href=\"https://visionae.fr\" target=\"_blank\" rel=\"noopener\" style=\"display: inline-block;\">\n                <img src=\"https://backoffice.visionae.fr/static/img/visionae-logo.png\" alt=\"Logo\" border=\"0\" width=\"216px\" style=\"display: block; width: 216px; max-width: 216px; min-width: 48px;\">\n              </a>\n            </td>\n          </tr>\n        </table>\n        <!--[if (gte mso 9)|(IE)]>\n        </td>\n        </tr>\n        </table>\n        <![endif]-->\n      </td>\n    </tr>\n    <!-- end logo -->\n\n    <!-- start hero -->\n    <tr>\n      <td align=\"center\" bgcolor=\"#e9ecef\">\n        <!--[if (gte mso 9)|(IE)]>\n        <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n        <tr>\n        <td align=\"center\" valign=\"top\" width=\"600\">\n        <![endif]-->\n        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 600px;\">\n          <tr>\n            <td align=\"left\" bgcolor=\"#ffffff\" style=\"padding: 36px 24px 0; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; border-top: 3px solid #d4dadf;\">\n              <h1 style=\"text-align: center; margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -1px; line-height: 48px;\">Reset Your Password</h1>\n            </td>\n          </tr>\n        </table>\n        <!--[if (gte mso 9)|(IE)]>\n        </td>\n        </tr>\n        </table>\n        <![endif]-->\n      </td>\n    </tr>\n    <!-- end hero -->\n\n    <!-- start copy block -->\n    <tr>\n      <td align=\"center\" bgcolor=\"#e9ecef\">\n        <!--[if (gte mso 9)|(IE)]>\n        <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n        <tr>\n        <td align=\"center\" valign=\"top\" width=\"600\">\n        <![endif]-->\n        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 600px;\">\n\n          <!-- start copy -->\n          <tr>\n            <td align=\"left\" bgcolor=\"#ffffff\" style=\"padding: 24px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;\">\n              <p style=\"margin: 0;\">Press the button below to reset your account password. If you didn't request a new password, you can safely delete this email.</p>\n              <p style=\"margin: 0;\"><i>This link will no longer be available in 30 minutes.</i></p>\n            </td>\n          </tr>\n          <!-- end copy -->\n\n          <!-- start button -->\n          <tr>\n            <td align=\"left\" bgcolor=\"#ffffff\">\n              <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n                <tr>\n                  <td align=\"center\" bgcolor=\"#ffffff\" style=\"padding: 12px;\">\n                    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n                      <tr>\n                        <td align=\"center\" bgcolor=\"#1a82e2\" style=\"border-radius: 6px;\">\n                          <a href=\"http://127.0.0.1:2000/reset_password/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZXNldF9wYXNzd29yZCI6MywiZXhwIjoxNTc0NjcwOTc0Ljk3NDc3NDF9.O5-u0g22mwfaU7sN1BIHHa_knqpOOTN3tgONAC166yM\" target=\"_blank\" rel=\"noopener\" style=\"display: inline-block; padding: 16px 36px; font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; color: #ffffff; text-decoration: none; border-radius: 6px;\">Reset your password</a>\n                        </td>\n                      </tr>\n                    </table>\n                  </td>\n                </tr>\n              </table>\n            </td>\n          </tr>\n          <!-- end button -->\n\n\n\n\n\n\n\n\n\n\n        </table>\n        <!--[if (gte mso 9)|(IE)]>\n        </td>\n        </tr>\n        </table>\n        <![endif]-->\n      </td>\n    </tr>\n    <!-- end copy block -->\n\n  </table>\n  <!-- end body -->\n\n</body>\n</html>"
        }
    ],
    "from": {
        "email": "[email protected]"
    },
    "personalizations": [
        {
            "to": [
                {
                    "email": "[email protected]"
                }
            ]
        },
        {
            "to": [
                {
                    "email": "[email protected]"
                }
            ]
        }
    ],
    "reply_to": {
        "email": "[email protected]"
    },
    "subject": "Password reset for Visionae"
}
127.0.0.1 - - [25/Nov/2019 09:06:15] "POST /v1/auth/user/forgot_password HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/python_http_client/client.py", line 174, in _make_request
    return opener.open(request, timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/seluj78/Projects/VisionaeAPI/visionae_api/routes/v1/authentication.py", line 86, in user_password_reset
    send_password_reset_mail(data["email"])
  File "/Users/seluj78/Projects/VisionaeAPI/visionae_api/utils/mail.py", line 58, in send_password_reset_mail
    sendmail_single_recipient(to_email=user_email, subject="Password reset for Visionae", html=html)
  File "/Users/seluj78/Projects/VisionaeAPI/visionae_api/utils/mail.py", line 34, in sendmail_single_recipient
    from_email=from_email, to_email=to_email, subject=subject, html=html
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/flask_sendgrid.py", line 77, in send_email
    return self.client.mail.send.post(request_body=self.get())
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/python_http_client/client.py", line 262, in http_request
    self._make_request(opener, request, timeout=timeout)
  File "/Users/seluj78/Projects/VisionaeAPI/venv/lib/python3.7/site-packages/python_http_client/client.py", line 178, in _make_request
    raise exc
python_http_client.exceptions.BadRequestsError: HTTP Error 400: Bad Request

Seluj78 avatar Nov 25 '19 08:11 Seluj78

I've nailed it down to your library, somewhere when you add to_emails using personalisation

Seluj78 avatar Nov 25 '19 08:11 Seluj78

I've found a workaround using https://github.com/hamano/flask-mail-sendgrid but your library is way quicker compared to the other one (we're talking seconds here)

Seluj78 avatar Nov 25 '19 08:11 Seluj78