2012-08-29 32 views
2

.ini文件金字塔烧杯缓存的问题 - 类型错误:int()函数的参数必须是字符串或数字,而不是 'NoneType'

cache.regions = default_term, second, short_term, long_term 
cache.type = memcached 
cache.url = 127.0.0.1:11211 
cache.second.expire = 1 
cache.short_term.expire = 60 
cache.default_term.expire = 300 
cache.long_term.expire = 3600 

__init__.py文件

from pyramid_beaker import set_cache_regions_from_settings 
def main(global_config, **settings): 
set_cache_regions_from_settings(settings) 
... 

test.py文件

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

cache_opts = { 
'cache.data_dir': '/tmp/cache/data', 
'cache.lock_dir': '/tmp/cache/lock', 
'cache.regions': 'short_term, long_term', 
'cache.short_term.type': 'ext:memcached', 
'cache.short_term.url': '127.0.0.1.11211', 
'cache.short_term.expire': '3600', 
'cache.long_term.type': 'file', 
'cache.long_term.expire': '86400', 
} 

cache = CacheManager(**parse_cache_config_options(cache_opts)) 

@cache.region('short_term', 'test') 
def test_method(*args, **kwargs): 

在执行上面的代码时会给出错误:

... 
File "c:\python27\lib\site-packages\python_memcached-1.48-py2.7.egg\memcache.py", line  1058, in __init__ 
self.port = int(hostData.get('port', 11211)) 
TypeError: int() argument must be a string or a number, not 'NoneType' 

任何想法可能会导致错误/或我失去了什么?

+0

看看'hostData [ '口']'。它似乎是'没有'......(我不知道为什么,我想我只是假设'hostData'是一个冠军...) – mgilson

+0

你削减了你的追踪的一大部分;大概它来自你的测试? –

回答

3

看看你的测试配置,url设置在它有一个错误:

'cache.short_term.url': '127.0.0.1.11211', 

注意,有在那里没有:结肠。使用memcached的模块,使用正则表达式,试图解析值,当您指定的值作为主机的方法设置port为无:

>>> host = '127.0.0.1.11211' 
>>> re.match(r'^(?P<host>[^:]+)(:(?P<port>[0-9]+))?$', host).groupdict() 
{'host': '127.0.0.1.11211', 'port': None} 

这是您的追溯来源。更改cache_opts字典阅读:

'cache.short_term.url': '127.0.0.1:11211', 

事情会很好地工作:

>>> host = '127.0.0.1:11211' 
>>> re.match(r'^(?P<host>[^:]+)(:(?P<port>[0-9]+))?$', host).groupdict() 
{'host': '127.0.0.1', 'port': '11211'} 
相关问题