dongweiming / lyanna

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

登陆报错 #54

Closed changjiong closed 3 years ago

changjiong commented 3 years ago

Exception occurred while handling uri: 'http://localhost:8000/auth' ... ...

File "/home/lsnn/.cache/pypoetry/virtualenvs/lyanna-uXFy9xdx-py3.8/lib/python3.8/site-packages/sanic_jwt/authentication.py", line 447, in generate_access_token return jwt.encode(payload, secret, algorithm=algorithm).decode("utf-8") AttributeError: 'str' object has no attribute 'decode'

去掉.decode("utf-8")就正常了

ziziran97 commented 3 years ago

你能正常添加作者吗?

我的添加作者后会报这个问题:

[2021-01-14 14:51:50 +0800] [95279] [ERROR] Exception occurred while handling uri: 'http://0.0.0.0:8000/api/user/new' Traceback (most recent call last): File ".../lyanna/venv/lib/python3.8/site-packages/sanic/app.py", line 942, in handle_request response = await response File ".../Python进阶/lyanna/venv/lib/python3.8/site-packages/sanic_jwt/decorators.py", line 114, in decorated_function return await _do_protection(*args, kwargs) File ".../lyanna/venv/lib/python3.8/site-packages/sanic_jwt/decorators.py", line 90, in _do_protection response = await response File ".../lyanna/views/admin.py", line 164, in new_user return await _user(request) File ".../lyanna/views/admin.py", line 208, in _user return response.json({'user': await user.to_sync_dict(), 'ok': ok}) # type: ignore File ".../lyanna/venv/lib/python3.8/site-packages/sanic/response.py", line 234, in json dumps(body, kwargs), TypeError: datetime.datetime(2021, 1, 14, 6, 50, 29, 546009) is not JSON serializable

ycq0125 commented 3 years ago

你能正常添加作者吗?

我的添加作者后会报这个问题:

[2021年1月14日十四时51分五十秒+0800] [95279] [错误]异常发生,同时处理URI: ' http://0.0.0.0:8000/api/user/new ' 回溯(最近通话最后一个) : 文件“.../lyanna/venv/lib/python3.8/site-packages/sanic/app.py”,第942行,在handle_request 响应=等待响应 文件“.../Python进阶/lyanna/venv” /lib/python3.8/site-packages/sanic_jwt/decorators.py”,第 114 行,在装饰 函数中返回 await _do_protection(*args, kwargs) 文件“.../lyanna/venv/lib/python3.8/ site-packages/sanic_jwt/decorators.py”,第 90 行,在 _do_protection response = await response 文件“.../lyanna/views/admin.py”,第 164 行,在 new_user 中 return await _user(request) File ".../lyanna/views/admin.py", line 208, in _user return response.json({'user': await user.to_sync_dict(), 'ok': ok}) # type: ignore File " .../lyanna/venv/lib/python3.8/site-packages/sanic/response.py", line 234, in json dumps (body, kwargs), TypeError: datetime.datetime(2021, 1, 14 , 6, 50, 29, 546009) 不是 JSON 可序列化的

image 更改成该方法即可,还可以看看怎么做的处理

xtet2008 commented 3 years ago

这个地方的报错是 json.dump识别不了原生Python 的datetime 类型数据,我修改过 orm 生成json 数据时候对 datetime 转换成 str 就好了。 另外请教下 发布文章的时候只能写纯文本吗 ? 怎么发布带格式的富文本?

发自我的iPhone

在 2021年8月15日,21:50,余半盏 @.***> 写道:

 你能正常添加作者吗?

我的添加作者后会报这个问题:

[2021年1月14日十四时51分五十秒+0800] [95279] [错误]异常发生,同时处理URI: ' http://0.0.0.0:8000/api/user/new ' 回溯(最近通话最后一个) : 文件“.../lyanna/venv/lib/python3.8/site-packages/sanic/app.py”,第942行,在handle_request 响应=等待响应 文件“.../Python进阶/lyanna/venv” /lib/python3.8/site-packages/sanic_jwt/decorators.py”,第 114 行,在装饰 函数中返回 await _do_protection(*args, kwargs) 文件“.../lyanna/venv/lib/python3.8/ site-packages/sanic_jwt/decorators.py”,第 90 行,在 _do_protection response = await response 文件“.../lyanna/views/admin.py”,第 164 行,在 new_user 中 return await _user(request) File ".../lyanna/views/admin.py", line 208, in _user return response.json({'user': await user.to_sync_dict(), 'ok': ok}) # type: ignore File " .../lyanna/venv/lib/python3.8/site-packages/sanic/response.py", line 234, in json dumps (body, kwargs), TypeError: datetime.datetime(2021, 1, 14 , 6, 50, 29, 546009) 不是 JSON 可序列化的

更改成该方法即可,还可以看看怎么做的处理

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

ycq0125 commented 3 years ago

这个地方的报错是 json.dump 识别不了类型原生 Python 的 datetime 数据,我修改过 orm json 生成数据对 datetime 转换成 str 就好了。另外请教下发布文章的时候可以写纯文本吗?怎么发布带格式的富文本? 发自我的iPhone 在 2021年8月15日,21:50,余半盏 @.> 写道:  你能正常添加作者吗? 我的添加作者后会报这个问题: [2021年1月14日十四时51分五十秒+0800] [95279] [错误]异常发生,同时处理URI: ' http://0.0.0.0:8000/api/user/new ' 回溯(最近通话最后一个) : 文件“.../lyanna/venv/lib/python3.8/site-packages/sanic/app.py”,第942行,在handle_request 响应=等待响应 文件“.../Python进阶/lyanna/venv” /lib/python3.8/site-packages/sanic_jwt/decorators.py”,第 114 行,在装饰 函数中返回 await _do_protection(args, kwargs) 文件“.../lyanna/venv/lib/python3.8/ site-packages/sanic_jwt/decorators.py”,第 90 行,在 _do_protection response = await response 文件“.../lyanna/views/admin.py”,第 164 行,在 new_user 中 return await _user(request) File ".../lyanna/views/admin.py", line 208, in _user return response.json({'user': await user.to_sync_dict(), 'ok': ok}) # type: ignore File " .../lyanna/venv/lib/python3.8/site-packages/sanic/response.py", line 234, in json dumps (body, **kwargs), TypeError: datetime.datetime(2021, 1, 14 , 6, 50, 29, 546009) 不是 JSON 可序列化的 更改成该方法即可,还可以看看怎么做的处理 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

抱歉,这些我并不清楚,刚接触该项目,可能需要问作者

dongweiming commented 3 years ago

啊 @drunkwretch @xtet2008 @ycq0125 @ziziran97 各位抱歉了,我挨个解决一下大家说的问题,有问题评论留言~

ycq0125 commented 3 years ago

您好,当我删除文章时好像对应的动态并不会删除,这个会改一下吗?还有就是相关依赖环境也有部分冲突,会更新吗?谢谢> 啊 @drunkwretch @xtet2008 @ycq0125 @ziziran97 各位抱歉了,我挨个解决一下大家说的问题,有问题评论留言~

dongweiming commented 3 years ago

@drunkwretch 看了下我本地环境也有这个代码但是正常运行,有点奇怪。这次我升级了全部依赖到最新版本,你删了虚拟环境目录重新安装试试吧,有问题再找我

ref: https://github.com/dongweiming/lyanna/commit/450b622d5139f0c4eb18ccf0ce24f86c36818724

dongweiming commented 3 years ago

@ziziran97 已经改正啦,拉最新代码再试试。 我原来封装一个函数处理json格式化, https://github.com/dongweiming/lyanna/blob/master/views/utils.py#L20 cc @xtet2008 @ycq0125

dongweiming commented 3 years ago

您好,当我删除文章时好像对应的动态并不会删除,这个会改一下吗?还有就是相关依赖环境也有部分冲突,会更新吗?谢谢> 啊 @drunkwretch @xtet2008 @ycq0125 @ziziran97 各位抱歉了,我挨个解决一下大家说的问题,有问题评论留言~

现在删除文章时会一并删除对应的动态啦。ref: https://github.com/dongweiming/lyanna/commit/38f41cf0b37c9634c5dff4ababe49d9823add205

另外更新了全部依赖,再看看有没有冲突的问题哈,有事留言给我