[THUDM/ChatGLM-6B]求大佬解决,我curl请求出现Internal Server Error

2024-05-10 525 views
3

在win10命令行中出现Internal Server Error 在服务器中显示如下: ERROR: Exception in ASGI application Traceback (most recent call last): File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 429, in run_asgi result = await app( # type: ignore[func-returns-value] File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in call return await self.app(scope, receive, send) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/fastapi/applications.py", line 276, in call await super().call(scope, receive, send) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/starlette/applications.py", line 122, in call await self.middleware_stack(scope, receive, send) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in call raise exc File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in call await self.app(scope, receive, _send) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in call raise exc File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in call await self.app(scope, receive, sender) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call raise e File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call await self.app(scope, receive, send) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/starlette/routing.py", line 718, in call await route.handle(scope, receive, send) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle await self.app(scope, receive, send) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/starlette/routing.py", line 66, in app response = await func(request) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/fastapi/routing.py", line 237, in app raw_response = await run_endpoint_function( File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/fastapi/routing.py", line 163, in run_endpoint_function return await dependant.call(**values) File "/home/bs2301/work/chatglm_6B/ChatGLM-6B/api.py", line 25, in create_item json_post_raw = await request.json() File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/site-packages/starlette/requests.py", line 244, in json self._json = json.loads(body) File "/home/bs2301/miniconda3/envs/chatglm/lib/python3.10/json/init.py", line 341, in loads s = s.decode(detect_encoding(s), 'surrogatepass') UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 9: invalid continuation byte

Steps To Reproduce

我先在centos7服务器中部署并运行了api.py,然后在win10命令行中输入:curl -H "Content-Type: application/json" -d "{"prompt": "你好", "history": []}" http://服务器的IP:8000

Environment
- OS:Windows10,Centos7
- Python:3.8
- Transformers:
- PyTorch:
- CUDA Support:True

回答

1

请问解决了吗,我也遇到相同问题

6

可能是请求体中prompt中文的问题,我当时在window10上部署运行了api.py,然后用git bash发了curl请求就报了这个错误。然后我把prompt中的内容替换成英文,比如说把“你好”改成“hello”,这种情况下能够正常返回结果。 后面我尝试用POSTMAN发送prompt带中文的请求,也能够正常返回。 我又尝试了使用windows的CMD发送请求,prompt也是中文,也能够正常返回。不过我的curl命令和你这边提供的不太一样: curl -X POST "http://127.0.0.1:8000" -H "Content-Type: application/json" -d "{\"prompt\": \"你好\", \"history\": []}"

5

可能是请求体中prompt中文的问题,我当时在window10上部署运行了api.py,然后用git bash发了curl请求就报了这个错误。然后我把prompt中的内容替换成英文,比如说把“你好”改成“hello”,这种情况下能够正常返回结果。 后面我尝试用POSTMAN发送prompt带中文的请求,也能够正常返回。 我又尝试了使用windows的CMD发送请求,prompt也是中文,也能够正常返回。不过我的curl命令和你这边提供的不太一样: curl -X POST "http://127.0.0.1:8000" -H "Content-Type: application/json" -d "{\"prompt\": \"你好\", \"history\": []}"

兄弟,我使用POSTMAN也可以发送请求并得到正确的返回值,可能是我的Curl环境有点问题吧

7

原来如此,希望官方把这个新的补进去

3

curl -X POST "http://127.0.0.1:8000" -H "Content-Type: application/json" -d "{\"prompt\": \"你好\", \"history\": []}"

感谢大佬 困扰一整天的问题终于解决了