Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

中文乱码问题 Chinese garbled character problem #504

Open
stuacct076 opened this issue Apr 28, 2023 · 1 comment
Open

中文乱码问题 Chinese garbled character problem #504

stuacct076 opened this issue Apr 28, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@stuacct076
Copy link

有办法解决JsonModal.get()中文序列化问题吗
Is there a way to solve the JsonModal.get() Chinese serialization problem?


framework:FastAPI

requirements.txt:

anyio==3.6.2
async-timeout==4.0.2
cffi==1.15.1
click==8.1.3
colorama==0.4.6
cryptography==40.0.2
fastapi==0.95.0
h11==0.14.0
hiredis==2.2.2
httptools==0.5.0
idna==3.4
more-itertools==8.14.0
pptree==3.1
pycparser==2.21
pydantic==1.10.7
python-dotenv==1.0.0
python-ulid==1.1.0
PyYAML==6.0
redis==4.5.4
redis-om==0.1.2
sniffio==1.3.0
starlette==0.26.1
types-pyOpenSSL==23.1.0.2
types-redis==4.5.4.1
typing_extensions==4.5.0
uvicorn==0.21.1
watchfiles==0.19.0
websockets==11.0.2
import uvicorn
from fastapi import FastAPI
from redis_om import JsonModel, get_redis_connection

app = FastAPI()


class User(JsonModel):
    name: str
    age: int

    class Meta:
        database = get_redis_connection(url="redis://:123456@localhost:6379/1", decode_responses=True)


@app.get("/save")
def save_user():
    user = User(pk="test", name="张三", age=18)
    return user.save()


@app.get("/get/{pk}")
def get_user():
    """
    {
        "pk": "test",
        "name": "å¼ ä¸\u0089", # 中文乱码 (Chinese garbled characters)
        "age": 18
    }
    """
    return User.get("test")


if __name__ == '__main__':
    uvicorn.run(app, host="127.0.0.1", port=8000)

Thanks

@chayim chayim added the bug Something isn't working label Apr 30, 2023
@stuacct076
Copy link
Author

I studied the source code and tried to solve this problem by the following way,
But I don't know if there's a hidden danger to this!!! 👀

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants