Skip to content

pre-commit run --all-files 报错:http.client.RemoteDisconnected #29

@niyunjun

Description

@niyunjun

国内使用socks5代理的朋友,会遇到上述问题。

报错完整信息如下:

Image

报错原因是:由于v2ray的代理协议是socks5,而urllib 请求远程 URL走的是http协议,不支持socks5协议。

以下是我的一个解决方案(本人环境是ubantu22.04, socks5代理)

第一步:编辑配置文件:

sudo nano /etc/privoxy/config

在配置文件中,找到或添加以下两行,确保它们没有被注释掉(行首没有 #):

listen-address 127.0.0.1:8123
forward-socks5t / 127.0.0.1:1080 .

将你的V2Ray_SOCKS5端口替换为你V2Ray配置中inbounds协议为socks的端口号(例如 1080)。注意:forward-socks5t 行末尾有一个点号.和空格,不要遗漏。

第二步:启动Privoxy服务并设置开机自启:

sudo systemctl start privoxy
sudo systemctl enable privoxy
sudo systemctl status privoxy # 检查状态,确保其为active (running)
第三步:设置环境变量,使用Privoxy的HTTP代理

export http_proxy="http://127.0.0.1:8123"
export https_proxy="http://127.0.0.1:8123"
为了长期使用,可添加到~/.bashrc文件的末尾

第四步:为防止DNS污染,也就是本地DNS解析不了国外的网站的ip。可在/etc/hosts文件中注明网站的ip
以golang官网为例

173.194.75.141 golang.org
216.58.200.238 golang.org
大功告成(如果还是出现上述报错,就再运行一次pre-commit run --all-files,这可能是网络代理的网络稳定性有关系)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions