Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TurboMail 3带1.0挂架-MailNotEnabledException_Python_Pylons - Fatal编程技术网

Python TurboMail 3带1.0挂架-MailNotEnabledException

Python TurboMail 3带1.0挂架-MailNotEnabledException,python,pylons,Python,Pylons,我正在尝试用1.0版的挂架安装TurboMail 3 跟随 我已将此添加到development.ini中 [DEFAULT] ... mail.on = true mail.manager = immediate mail.transport = smtp mail.smtp.server = localhost 我的app_globals.py看起来像: """The application's Globals object""" from beaker.cache import C

我正在尝试用1.0版的挂架安装TurboMail 3

跟随

我已将此添加到development.ini中

[DEFAULT]
...
mail.on = true
mail.manager = immediate 
mail.transport = smtp 
mail.smtp.server = localhost
我的app_globals.py看起来像:

"""The application's Globals object"""

from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options

class Globals(object):

    def __init__(self, config):
        self.cache = CacheManager(**parse_cache_config_options(config))

     from turbomail.adapters import tm_pylons
     tm_pylons.start_extension()
我的控制器具有以下方法:

def submit(self):
    message = Message("from@example.com", "to@example.com", "Hello World")
    message.plain = "TurboMail is really easy to use."
    message.send()
问题是,调用message.send()时,我遇到此错误:

MailNotEnabledException: An attempt was made to use a facility of the TurboMail framework but outbound mail hasn't been enabled in the config file [via mail.on]
我不知道我错过了什么? 根据文件,一切似乎都正常


多亏了Pylons 1.0对配置在全局对象中的存储方式(以及存储时间)进行了一些向后不兼容的更改。在这种情况下,在实例化Globals对象时,不再加载配置。相反,您必须将代码更改为以下内容:

import atexit
from turbomail import interface
from turbomail.adapters import tm_pylons
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options

class Globals(object):
    def __init__(self, config):
        self.cache = CacheManager(**parse_cache_config_options(config))

        atexit.register(tm_pylons.shutdown_extension)
        interface.start(tm_pylons.FakeConfigObj(config))
上面的代码(atexit和interface.start)正是start_extension()代码所做的

我将发布一个更新的TurboMail,以允许将配置作为参数传递给start_extension(),这将以一种更理智的方式解决这个问题