版本兼容问题
之前没考虑到版本问题,django、channel和python都是用的最新的,导致channel不能正常调用websocket,出现如下404的报错:
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[01/Feb/2023 16:45:49] "GET /workload/terminal/?namespace=XXX-dev&pod_name=fr-XXX-admin-5745896779-ll55x&containers=fr-XXX-admin HTTP/1.1" 200 2478
Not Found: /workload/terminalXXX-dev/fr-XXX-admin-5745896779-ll55x/fr-XXX-admin/
[01/Feb/2023 16:45:49] "GET /workload/terminal/XXX-dev/fr-toolchain-admin-5745896779-ll55x/frXXX-admin/?auth_type=kubeconfig&token=43007d40a63802cXXXX0dcea01f84155 HTTP/1.1" 404 5989
由于使用的是python3.10,django和channel版本要迁就python版本,根据[文档]介绍(https://docs.djangoproject.com/en/4.1/faq/install/#:~:text=What%20Python%20version%20should%20I,of%20Python%203%20is%20recommended.),最终版本设定如下
Django 3.2.17
Python 3.10
Channels 3.0.5
redis密码特殊字符问题
django的setting中设置redis,配置密码时有特殊字符会报错,通过以下方式,可以解决特殊字符问题:
redis_password = quote("d&4!Bzf*&%P1r")
#"hosts": [{"address": ('127.0.0.1', 6379), "password": 'nEdfaP1r'}]
ASGI_APPLICATION = 'devops.routing.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [f"redis://:{redis_password}@127.0.0.1:6379/0"],
},
},
}