pyramid beaker cache issue - TypeError: int() argument must be a string or a number, not 'NoneType'
Domanda
.ini file
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
file
from pyramid_beaker import set_cache_regions_from_settings
def main(global_config, **settings):
set_cache_regions_from_settings(settings)
...
test.py file
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):
On executing the above code it gives error:
...
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'
Any idea what may be causing the error/ or I am missing anything ??
Soluzione
Take a look at your test configuration, the url
setting has an error in it:
'cache.short_term.url': '127.0.0.1.11211',
Note that there is no :
colon in there. The memcached module you use, uses regular expressions to try and parse that value, and that method sets port
to None when you specify that value as a host:
>>> 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}
which is the source of your traceback. Change the cache_opts
dict to read:
'cache.short_term.url': '127.0.0.1:11211',
and things will work fine:
>>> host = '127.0.0.1:11211'
>>> re.match(r'^(?P<host>[^:]+)(:(?P<port>[0-9]+))?$', host).groupdict()
{'host': '127.0.0.1', 'port': '11211'}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow