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

@githubnext/github-copilot-cli CLI认证失败(HTTP 502错误)

问题:GitHub Copilot CLI 认证时反复出现502错误

已通过以下命令成功全局安装GitHub Copilot CLI:

npm install -g @githubnext/github-copilot-cli

执行github-copilot-cli auth启动设备认证流程,按提示在https://github.com/login/device完成授权后,反复收到502错误,错误详情如下:

Failed to authenticate: Request failed with status code 502, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>502 - Web server received an invalid response while acting as a gateway or proxy server.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
 <div class="content-container"><fieldset>
  <h2>502 - Web server received an invalid response while acting as a gateway or proxy server.</h2>
  <h3>There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.</h3>
 </fieldset></div>
</div>
</body>
</html>

确认当前未使用代理环境,多次尝试均失败,寻求可行的解决方法。


解决方法

1. 排查GitHub服务状态

502错误多为GitHub端服务临时故障,先确认Copilot相关服务是否正常。若存在服务中断或维护,等待一段时间后重试即可。

2. 清理CLI缓存并重新安装认证

  • 卸载当前Copilot CLI:
    npm uninstall -g @githubnext/github-copilot-cli
    
  • 删除CLI缓存目录:
    • macOS/Linux:rm -rf ~/.github-copilot-cli
    • Windows:rd /s /q %USERPROFILE%\.github-copilot-cli
  • 重新安装并启动认证:
    npm install -g @githubnext/github-copilot-cli
    github-copilot-cli auth
    

3. 手动使用个人访问令牌(PAT)认证

如果设备流认证持续失败,可通过手动生成PAT绕过设备认证流程:

  • 生成包含copilot权限的GitHub个人访问令牌
  • 设置环境变量注入令牌:
    • macOS/Linux:
      export GITHUB_TOKEN="你的PAT令牌内容"
      
    • Windows(PowerShell):
      $env:GITHUB_TOKEN="你的PAT令牌内容"
      
  • 再次执行github-copilot-cli auth,CLI会自动读取环境变量完成认证

4. 排查本地网络问题

  • 切换网络环境(如从WiFi切换到手机热点),排除运营商网关故障
  • 刷新本地DNS缓存:
    • macOS:sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
    • Windows:ipconfig /flushdns
    • Linux:sudo systemd-resolve --flush-caches

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 12:17:30