无法使用Google Cloud身份验证而非邮件设置

时间:2018-05-25 14:21:40

标签: python flask google-cloud-platform flask-security flask-mail

所以我正在尝试配置烧瓶安全性,以便在我注册时发送确认电子邮件,但它似乎不起作用。我想使用我从Google Cloud生成的凭据,而不是设置邮件设置(MAIL_SERVER,MAIL_PASSWORD等)。

这是我的代码:

class BaseConfig:
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_RECORD_QUERIES = False
SQLALCHEMY_EXPIRE_ON_COMMIT = False

MARSHMALLOW_STRICT = True
MARSHMALLOW_DATEFORMAT = 'rfc'

SECRET_KEY = 'secret_key'
SECURITY_LOGIN_SALT = 'test'
SECURITY_PASSWORD_HASH = 'pbkdf2_sha512'
SECURITY_TRACKABLE = True
SECURITY_PASSWORD_SALT = 'something'
WTF_CSRF_ENABLED = False
SECURITY_REGISTERABLE = True
SECURITY_CONFIRMABLE = True
SECURITY_RECOVERABLE = True
SECURITY_TOKEN_AUTHENTICATION_HEADER = 'Authorization'
MAX_AGE = 86400
GOOGLE_APPLICATION_CREDENTIALS = '.\google_credentials_etc.json' 

但每次我注册时都会遇到这个例外:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.6/site-packages/flask_restful/__init__.py", line 273, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.6/site-packages/flask_restful/__init__.py", line 273, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/site-packages/flask_restful/__init__.py", line 273, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.6/site-packages/flask_restful/__init__.py", line 273, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.6/site-packages/flask_security/decorators.py", line 225, in wrapper
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/flask_security/views.py", line 117, in register
    user = register_user(**form.to_dict())
  File "/usr/local/lib/python3.6/site-packages/flask_security/registerable.py", line 41, in register_user
    user=user, confirmation_link=confirmation_link)
  File "/usr/local/lib/python3.6/site-packages/flask_security/utils.py", line 341, in send_mail
    mail.send(msg)
AttributeError: 'NoneType' object has no attribute 'send'

我该如何解决这个问题?

感谢。

0 个答案:

没有答案