文章内容

2019/12/23 16:01:40,作 者: 黄兵

DataError: Invalid input of type: 'NoneType'

最近使用Python查询Redis数据库的时候,出现如下错误:

DataError: Invalid input of type: 'NoneType'. Convert to a byte, string or number first.

出现问题的代码:

if redis_client.sismember('U', get_u):
    return redirect(url_for('ad', seo_link='Slaim'), 302)

出现这个问题的主要原因是:

首先获取get_u,如果get_uNone,则会报如上错误。

解决方案:

首先需要判断是否为None

if get_user_agent is not None:
    if redis_client.sismember('U', get_u):
        return redirect(url_for('ad', seo_link='Slaim'), 302)

这样就可以解决这个问题。


参考资料:

1、Python连接Redis数据库插入数据出现错误:DataError: Invalid input of type: 'NoneType'


黄兵个人博客原创。

转载请注明出处:黄兵个人博客 - DataError: Invalid input of type: 'NoneType'

分享到:

发表评论

评论列表