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

Ubuntu虚拟机调用Microsoft Graph API遇ETIMEOUT错误求助

Ubuntu VMware虚拟机中Node.js调用Microsoft Graph API出现ETIMEDOUT错误排查

在Ubuntu VMware虚拟机中使用Node.js 20.19.2搭配Axios调用Microsoft Graph API时,持续出现ETIMEDOUT错误,Windows主机运行相同代码可正常执行,已尝试多种方法(包括ChatGPT提供的方案)均未解决。

测试代码(test.js)

import axios from "axios";

let data = JSON.stringify({
  "subject": "New Event",
  "body": {
    "contentType": "HTML",
    "content": "Does next month work for you?"
  },
  "start": {
    "dateTime": "2025-06-10T12:00:00",
    "timeZone": "Pacific Standard Time"
  },
  "end": {
    "dateTime": "2025-06-10T14:00:00",
    "timeZone": "Pacific Standard Time"
  }
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  host: 'graph.microsoft.com',
  url: 'https://graph.microsoft.com/v1.0/me/events',
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': 'Bearer token'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

错误日志

Network error: AggregateError [ETIMEDOUT]: 
    at internalConnectMultiple (node:net:1122:18)
    at internalConnectMultiple (node:net:1190:5)
    at Timeout.internalConnectMultipleTimeout (node:net:1716:5)
    at listOnTimeout (node:internal/timers:583:11)
    at process.processTimers (node:internal/timers:519:7) {
  code: 'ETIMEDOUT',
  [errors]: [
    Error: connect ETIMEDOUT 20.190.144.169:443
        at createConnectionError (node:net:1652:14)
        at Timeout.internalConnectMultipleTimeout (node:net:1711:38)
        at listOnTimeout (node:internal/timers:583:11)
        at process.processTimers (node:internal/timers:519:7) {
      errno: -110,
      code: 'ETIMEDOUT',
      syscall: 'connect',
      address: '20.190.144.169',
      port: 443
    },
...

排查与解决建议

  • 检查VMware虚拟机网络模式:切换为桥接模式(Bridged),让虚拟机直接接入主机所在网络,避免NAT模式的转发限制。
  • 测试虚拟机网络连通性:
    • 执行ping graph.microsoft.com确认域名解析正常
    • 执行telnet graph.microsoft.com 443验证443端口可访问
  • 临时关闭Ubuntu防火墙:执行sudo ufw disable后重试,若恢复正常,添加放行规则sudo ufw allow out 443/tcp
  • 同步代理配置(若主机使用代理):在Axios配置中添加代理参数:
    proxy: {
      host: '你的代理IP',
      port: 代理端口,
      protocol: 'https'
    }
    
  • 临时禁用Node.js证书验证(仅测试用):执行NODE_TLS_REJECT_UNAUTHORIZED=0 node test.js重试
  • 重置VMware网络适配器:在虚拟机设置中重置网络适配器,重启后再测试

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 23:50:18