You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mercurial hgweb报“仅支持编码字符串”错误求助

解决Mercurial hgweb服务“Mercurial only supports encoded strings: 'hgweb.config'”错误

这个错误源于Python 3与Python 2的字符串编码处理差异——旧服务器大概率使用Python 2,而新服务器的Python 3对字符串/字节流的区分更严格。以下是针对性修复方案:

1. 修改hgweb.cgi脚本

找到脚本中读取hgweb.config的代码段,通常是类似如下的写法:

config = mercurial.hgweb.hgweb.config('hgweb.config')

将其替换为明确指定编码读取配置的代码:

# 以UTF-8编码读取配置文件内容
with open('hgweb.config', 'r', encoding='utf-8') as f:
    config_content = f.read()
# 用字符串内容初始化配置
config = mercurial.hgweb.hgweb.config(config_content)

同时检查脚本开头的shebang行,确保指向Python 3解释器:

#!/usr/bin/env python3

2. 确保hgweb.config文件编码为UTF-8

用以下命令检查并转换文件编码:

# 查看当前文件编码
file -i hgweb.config
# 若不是UTF-8,执行转换(将"原编码"替换为实际编码,比如gbk)
iconv -f 原编码 -t utf-8 hgweb.config > hgweb.config.new
mv hgweb.config.new hgweb.config

3. 验证文件权限

确保Apache运行用户(通常是www-data)对hg相关文件及仓库目录有读取权限:

chown -R www-data:www-data /path/to/your/hg/files/
chmod -R 755 /path/to/your/hg/files/

4. 重启服务测试

重启Apache后再次访问服务地址:

systemctl restart apache2

内容的提问来源于stack exchange,提问作者ScottD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 05:33:10