侧边栏壁纸
  • 累计撰写 185 篇文章
  • 累计创建 77 个标签
  • 累计收到 17 条评论

目 录CONTENT

文章目录

vscode通过Remote-SSH插件连接Linux时报Error: XHR failed错误

码峰
2024-02-05 / 0 评论 / 0 点赞 / 401 阅读 / 810 字 / 正在检测是否收录...
广告 广告

前言

最近在使用vscode通过Remote-SSH插件连接Linux时报Error: XHR failed错误,看输出的操作记录,应该是vscode-server下载由于不是https而失败了,折腾了半个小时,终于解决了,记录在这里供参考。

报错信息

报错1:Could not establish connection to : XHR failed.
报错2:卡在Setting up SSH Host XXX:Copying VS Code Server to host with scp
个人认为这两种报错其实是一种问题,都是服务器端的vscode-server下载受到限制(例如服务器网络不能fq,非常常见),可以采取离线下载server而后上传到服务器指定位置的方法
具体报错信息如下:

[18:37:53.588] > Acquiring lock on /home/ferris/.vscode-server/bin/6c3e3dba23e8fadc360aed75ce363ba
> 185c49794/vscode-remote-lock.ferris.6c3e3dba23e8fadc360aed75ce363ba185c49794     
[18:37:53.619] > Installing to /home/ferris/.vscode-server/bin/6c3e3dba23e8fadc360aed75ce363ba185c
> 49794...
> 9d38e514b207%%1%%
[18:37:53.634] > Downloading with wget
[18:37:53.905] > wget download failed
> 错误: 没有匹配的证书主体别名 (Subject Alternative Name)。 请求的主机名为 “vscode
> .cdn.azure.cn”。 要以不安全的方式连接至 vscode.cdn.azure.cn,使用“--no-check-cer
> tificate”。
> printenv:
>     SHELL=/bin/bash
>     LANGUAGE=zh_CN:zh
>     PWD=/home/ferris/.vscode-server/bin/6c3e3dba23e8fadc360aed75ce363ba185c49794 
>     LOGNAME=ferris
>     XDG_SESSION_TYPE=tty
>     MOTD_SHOWN=pam
>     HOME=/home/ferris
>     LANG=zh_CN.UTF-8
>     VSCODE_AGENT_FOLDER=/home/ferris/.vscode-server
>     SSH_CONNECTION=192.168.1.3 41872 192.168.1.97 22
>     XDG_SESSION_CLASS=user
>     USER=ferris
>     SHLVL=0
>     XDG_SESSION_ID=21
>     XDG_RUNTIME_DIR=/run/user/1000
>     SSH_CLIENT=192.168.1.3 41872 22
>     PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
> :/usr/local/games:/snap/bin
>     DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
>     OLDPWD=/home/ferris
>     _=/usr/bin/printenv
> Trigger local server download
[18:37:53.913] > 
> 9d38e514b207:trigger_server_download
> platform==linux==
> vscodeArch==x64==
> destFolder==/home/ferris/.vscode-server/bin/==
> destFolder2==6c3e3dba23e8fadc360aed75ce363ba185c49794==
> 9d38e514b207:trigger_server_download_end
> Waiting for client to transfer server archive...
> Waiting for /home/ferris/.vscode-server/bin/6c3e3dba23e8fadc360aed75ce363ba185c49
> 794/vscode-scp-done.flag and vscode-server.tar.gz to exist
[18:37:53.914] Got request to download on client for {"platform":"linux","arch":"x64","destFolder":"/home/ferris/.vscode-server/bin/6c3e3dba23e8fadc360aed75ce363ba185c49794"}
[18:37:53.914] Downloading VS Code server locally...
[18:37:53.929] > 
> 
[18:37:54.700] Resolver error: Error: XHR failed
    at y.onerror (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:77:1261)
[18:37:54.714] ------

解决方案

Step1:查看vscode当前版本的commit id,在vscode->关于中可以看到,如下图:
image
我这里是:6c3e3dba23e8fadc360aed75ce363ba185c49794
其中提交项目即为commit id,或者登陆到服务器$HOME文件夹中,ls -a查看隐藏目录$HOME/.vscode-server/bin下的文件夹名称

Step2:在该链接下手动下载server的压缩包vscode-server-linux-x64.tar.gz

https://update.code.visualstudio.com/commit:${COMMIT_ID}/server-linux-x64/stable

注意将${COMMIT_ID}替换为你的具体的提交序列号

Step3:上传该压缩包到服务器$HOME/.vscode-server/bin

Step4:解压,并更改解压文件夹名字

cd ~/.vscode-server/bin
tar -zxf vscode-server-linux-x64.tar.gz
mv vscode-server-linux-x64 ${COMMIT_ID}

注意将${COMMIT_ID}替换为具体的提交序列号,然后尝试重新连接,即可解决问题。

0
广告 广告

评论区