iuiaoin / wechat-gptbot

A wechat robot based on ChatGPT with no risk, very stable! 🚀
MIT License
583 stars 115 forks source link

[Bug]: http://127.0.0.1:5555/api/get_personal_info 返回contents错误 #69

Closed ziran33 closed 1 year ago

ziran33 commented 1 year ago

Search for answers in existing issues

Python version

python 3.10

Issue description

http://127.0.0.1:5555/api/get_personal_info 返回contents错误

Repro steps

api.py文件中的 def fetch(path, data): base_data = { "id": gen_id(), "type": "null", "roomid": "null", "wxid": "null", "content": "null", "nickname": "null", "ext": "null", } base_data.update(data) url = f"http://{const.IP}:{const.PORT}/{path}" response = requests.post(url, json={"para": base_data}, timeout=5)

response 返回的内容出错, {'content': '[json.exception.type_error.316] invalid UTF-8 byte at index 0: 0x90', 'id': '20230728145737', 'receiver': 'CLIENT', 'sender': 'SERVER', 'srvid': 1, 'status': 'FAILED', 'time ': '2023-07-28 14:57:37', 'type': 6500}

编码错误,需要调整一下服务端。 导致无法输出 logger.info( f""" wechat login info:

            nickName: {content['wx_name']}
            account: {content['wx_code']}
            wechatId: {content['wx_id']}
            startTime: {response['time']}
            """
    )

信息。

整个代码无法继续执行下去。

Relevant log output

无法正常执行
Niomax32 commented 1 year ago

I just encountered the exact same issue. And I fixed it by changing my system region setting, which is kind of funny.

The error itself indicates something wrong with the utf-8 encoding, it's a vague error to be honest. I tried to tune up my requests multiple times but still got same error. Luckily, I got another environment running the bot normally, so started to compare two environments and found this system setting difference:

image

On the other working environment, the Beta function box of Unicode UTF8 is not checked and it encourages me trying to uncheck the box and reboot my problematic Windows environment. And poof, the utf-8 byte error is gone magically after the reboot.

Didn't track down the root cause though, it might still be helpful double checking your utf8 encoding settings. Good luck!

iuiaoin commented 1 year ago

@ziran33 invalid UTF-8 indicates your json file is not UTF-8 format, you can convert your config.json file to UTF-8 and try again. Normally, you can just open the json file with notepad++(or else) and save with UTF-8