1

Sendgrid でパスワード リセット メールを送信しようとしています。

エラーのスタック トレースは次のとおりです。

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\lib\webapp2-
2.5.2\webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-
2.5.2\webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-
2.5.2\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-
2.5.2\webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "C:\Program Files\Google\google_appengine\lib\webapp2-
2.5.2\webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-
2.5.2\webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "C:\Users\C\PycharmProjects\alpha\u\user.py", line 121, in post
    response = sg.client.mail.send.post(request_body=mail.get())
  File "C:\Users\C\PycharmProjects\alpha\python_http_client\client.py", 
line 227, in http_request
    return Response(self._make_request(opener, request))
  File "C:\Users\C\PycharmProjects\alpha\python_http_client\client.py", 
line 161, in _make_request
    raise exc
UnauthorizedError

プロジェクトに sendgrid と python-http-client の両方をインポートしました。(なぜこれを個別にインポートする必要があるのですか?)

Sendgrid デモから取得したテスト コードを次に示します。

class PasswordResetHandler(BaseHandler):
"""
handler to reset the users password.
also to verify if the user email is in the database
"""
def post(self):
    email = self.request.get("email_for_reset")

    sg = sendgrid.SendGridAPIClient(apikey=os.environ.get(SENDGRID_API_KEY))
    from_email = Email("email@example.com")
    to_email = Email(email)
    subject = "Sending with SendGrid is Fun"
    content = Content("text/plain", "and easy to do anywhere, even with Python")
    mail = Mail(from_email, subject, to_email, content)
    response = sg.client.mail.send.post(request_body=mail.get())
    self.redirect('/u/password-reset-confirmation')

ここで何が起こっているのか誰でも助けてもらえますか?

ありがとう。

4

2 に答える 2