dongweiming / lyanna

My Blog Using Sanic
http://www.dongwm.com
GNU General Public License v3.0
637 stars 173 forks source link

fix:TypeError when initial RedisSettings #30

Closed vimiix closed 5 years ago

vimiix commented 5 years ago

Config:

REDIS_URL = 'redis://localhost:6379'

Traceback

Traceback (most recent call last):
  File "/home/ubuntu/lyanna/venv/lib/python3.6/site-packages/sanic/app.py", line 750, in handle_request
    response = await response
  File "/home/ubuntu/lyanna/views/j.py", line 25, in wrapped
    return await f(request, *args, **kwargs)
  File "/home/ubuntu/lyanna/views/j.py", line 35, in create_comment
    comment = await post.add_comment(user['gid'], content)
  File "/home/ubuntu/lyanna/models/comment.py", line 71, in add_comment
    redis = await create_pool(RedisSettings.from_url(REDIS_URL))
  File "/home/ubuntu/lyanna/models/utils.py", line 180, in from_url
    return cls(url['host'], url['port'], int(url['database']),
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

When the database is not specified in REDIS_URL, it will be parsed to None value. So I fixed it by setting default value 0.

dongweiming commented 5 years ago

@vimiix Thanks!