tankwyn / WPS-Zotero

An add-on for WPS Writer to integrate with Zotero.
GNU General Public License v3.0
181 stars 13 forks source link

linux版wps发生编码报错 #23

Open dsw676676 opened 7 months ago

dsw676676 commented 7 months ago

基本信息

运行系统:archlinux x86_64

桌面环境:kde plasma

wps版本:11.1.0.11719-1

zotero版本:6.0.35-2

运行问题

wps GUI端报错 WPS-zotero: Network error occurred, is Zotero running?

图片

关闭系统代理,并检查端口确认端口无冲突后,问题仍然存在。

检查log文件发现proxy.py无法解析编码:

  File "/home/dsw/下载/PC/WPS-Zotero-main/proxy.py", line 172, in main
    server.run()
  File "/home/dsw/下载/PC/WPS-Zotero-main/proxy.py", line 77, in run
    self.on_recv(s, data)
  File "/home/dsw/下载/PC/WPS-Zotero-main/proxy.py", line 131, in on_recv
    head = head_raw.decode('utf8').split("\r\n")
           ^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x98 in position 0: invalid start byte

解决方案

将proxy.py的第131行替换为:

head = head_raw.decode('utf8', errors='ignore').split("\r\n")

此时不再出现报错,且目前未发现对引用功能的不利影响。

tankwyn commented 7 months ago

看看终端locale的输出?

dsw676676 commented 7 months ago
$ locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
dsw676676 commented 7 months ago

不是很了解字符编码,难道是系统编码的问题?

tankwyn commented 7 months ago

出问题的那个文献可以导出引用传上来吗?你的wps可能用的gbk编码

在 2024年4月8日,下午12:00,Tuan @.***> 写道:



不是很了解字符编码,难道是系统编码的问题?

— Reply to this email directly, view it on GitHubhttps://github.com/tankwyn/WPS-Zotero/issues/23#issuecomment-2041818364, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADK37UXSDDKJNJK3VTDSJY3Y4II5JAVCNFSM6AAAAABF3FJ7PKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRHAYTQMZWGQ. You are receiving this because you commented.Message ID: @.***>

dsw676676 commented 7 months ago

我进行了多次测试,但问题似乎不是某一篇文献导致的。当文献数量增加到一定程度时,NetworkError就会偶发地出现。

尝试检查了导致问题的proxy.py文件,发现on_recv()函数中的head_raw变量似乎偶尔会接收到意外的值。

class ProxyServer:
    #%% 省略 %%#
    def on_recv(self, s, data):
        logging.debug('received data: {}'.format(data))
        if data.startswith(b'POST /stopproxy'):
            logging.info('received stopping command!')
            s.close()
            self.running = False
            return
        if s not in self.channels:
            self.on_close(s)
            return
        # Parse HEAD
        head_raw, _, body_raw = data.partition(b"\r\n\r\n")
        head = head_raw.decode('utf8').split("\r\n")
        if "[1]" in head[0]: print('*')
        else: print("-")
        request = head[0]
        headers = {t[0]: t[1] for t in map(lambda x: x.split(': ') + [''], head[1:])}
        if s.getpeername() in self.clients:
            # Preflight responses
            logging.info('message received on client {}'.format(s.getpeername()))
            if data.startswith(b'OPTIONS') and 'Origin' in headers and 'Access-Control-Request-Method' in headers:
                for k,v in PREFLIGHT_HEADERS.items():
                    headers[k] = v
                data = '\r\n'.join(['HTTP/1.0 200 OK'] + [': '.join(h) for h in headers.items()] + ['', '']).encode('utf8') + body_raw
                s.sendall(data)
                logging.info('responded to a preflight request')
                return
        else:
            logging.info('message received from zotero')
            # CORS
            headers['Access-Control-Allow-Origin'] = '*'
            data = '\r\n'.join([request] + [': '.join(h) for h in headers.items()] + ['', '']).encode('utf8') + body_raw
        self.channels[s].send(data)
        logging.info('responded to {}'.format(self.channels[s].getpeername()))

decode("utf-8", errors='ignore')强行解码结果

['环境规制在给一些企业带来直接费用的同时,也会激发一些创新,可以部分或全部地抵消这些费用成本。这暗合了迈克尔.波特的观点——环境规制能使受规制的企业受益。企业内生的技术变化会使波特假设变得可行,而外生的环境政策如果产生与波特假设一致的效果,则该政策不一定最佳。海尔通过自主创新,实现了从遵守标准到制定标准,其产品成功地进入了欧美市场,表明全球经济一体化背景下,发展中国家的企业要应对发达国家实施的技术壁垒,只有通过自主创新,才能实现竞争优势。\",\"container-title\":\"中国工业经济\",\"DOI\":\"10.19581/j.cnki.ciejournal.2006.03.013\",\"ISSN\":\"1006-480X\",\"issue\":\"3\",\"language\":\"zh-CN\",\"note\":\"original-container-title: China Industrial Economics\\ndownload: 9711\\nalbum: 基础科学;经济与管理科学\\nCLC: F224\\nCNKICite: 896\\ndbcode: CJFQ\\ndbname: CJFD2006\\nfilename: GGYY200603012\\npublicationTag: 北大核心, CSSCI, AMI顶级, 社科基金资助期刊\\nCIF: 24.929\\nAIF: 18.213\",\"page\":\"100-106\",\"source\":\"CNKI\",\"title\":\"环境规制与企业自主创新——基于波特假设的企业竞争优势构建\",\"author\":[{\"literal\":\"黄德春\"}]]



我不清楚这是否和我遇到的问题有关。
70iscoolest commented 7 months ago

改了131行也没用咋办

Distributor: Ubuntu 22.04.4 LTS python version: python 3.7.12 (conda)

卸载重装几次都不行

70iscoolest commented 7 months ago

改了131行也没用咋办

Distributor: Ubuntu 22.04.4 LTS python version: python 3.7.12 (conda)

卸载重装几次都不行

额,第二天重新打开之后又突然可以了,虽然不知道为什么

tankwyn commented 7 months ago

@dsw676676 @70iscoolest 重新下载安装试下,应该修复了

dsw676676 commented 5 months ago

重新安装后,似乎确实没有再出现问题。非常感谢作者!辛苦了!