AxiosError:连接 ETIMEDOUT 取决于操作系统设置

AxiosError: connect ETIMEDOUT depends on OS settings

提问人:yakob 提问时间:7/21/2023 更新时间:7/21/2023 访问量:218

问:

我正在尝试向google.finance发送请求,并从一台笔记本电脑(Windows操作系统)收到响应。好的,从另一台笔记本电脑(也是 Windows 操作系统)我收到连接错误。有人可以帮我解释一下发生了什么吗?

这是我使用命令“节点文件名.js”运行的文件的一部分:

const axios = require('axios'); //axios I'm already installed

const scrape = async(symbol) => 
{
    const result = await axios(`http://www.google.com/finance/quote/eth-USD`);
    //and here I'm already fallen
}

我得到的错误:

AxiosError: connect ETIMEDOUT 2XXX:XXXX:XXXX:808::2004:80
    at AxiosError.from (C:\Users\yakovm\Desktop\NodeJs\node_modules\axios\dist\node\axios.cjs:836:14)
    at RedirectableRequest.handleRequestError (C:\Users\yakovm\Desktop\NodeJs\node_modules\axios\dist\node\axios.cjs:3010:25)
    at RedirectableRequest.emit (node:events:513:28)
    at eventHandlers.<computed> (C:\Users\yakovm\Desktop\NodeJs\node_modules\follow-redirects\index.js:14:24)
    at ClientRequest.emit (node:events:513:28)
    at Socket.socketErrorListener (node:_http_client:502:9)      
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)    
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  port: 80,
  address: '2XXX:XXXX:XXXX:808::2004',
  syscall: 'connect',
  code: 'ETIMEDOUT',
  errno: -4039,
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [ 'xhr', 'http' ],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    env: { FormData: [Function], Blob: [class Blob] },
    validateStatus: [Function: validateStatus],
    headers: AxiosHeaders {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/1.4.0',
      'Accept-Encoding': 'gzip, compress, deflate, br'
    },
    url: 'http://www.google.com/finance/quote/ETH-USD',
    method: 'get',
    data: undefined
  },
  request: <ref *1> Writable {
    _writableState: WritableState {
      objectMode: false,
      highWaterMark: 16384,
      finalCalled: false,
      needDrain: false,
      ending: false,
      ended: false,
      finished: false,
      destroyed: false,
      decodeStrings: true,
      defaultEncoding: 'utf8',
      length: 0,
      writing: false,
      corked: 0,
      sync: true,
      bufferProcessing: false,
      onwrite: [Function: bound onwrite],
      writecb: null,
      writelen: 0,
      afterWriteTickInfo: null,
      buffered: [],
      bufferedIndex: 0,
      allBuffers: true,
      allNoop: true,
      pendingcb: 0,
      constructed: true,
      prefinished: false,
      errorEmitted: false,
      emitClose: true,
      autoDestroy: true,
      errored: null,
      closed: false,
      closeEmitted: false,
      [Symbol(kOnFinished)]: []
    },
    _events: [Object: null prototype] {
      response: [Function: handleResponse],
      error: [Function: handleRequestError],
      socket: [Function: handleRequestSocket]
    },
    _eventsCount: 3,
    _maxListeners: undefined,
    _options: {
      maxRedirects: 21,
      maxBodyLength: Infinity,
      protocol: 'http:',
      path: '/finance/quote/ETH-USD',
      method: 'GET',
      headers: [Object: null prototype],
      agents: [Object],
      auth: undefined,
      family: undefined,
      lookup: undefined,
      beforeRedirect: [Function: dispatchBeforeRedirect],
      beforeRedirects: [Object],
      hostname: 'www.google.com',
      port: '',
      agent: undefined,
      nativeProtocols: [Object],
      pathname: '/finance/quote/ETH-USD'
    },
    _ended: true,
    _ending: true,
    _redirectCount: 0,
    _redirects: [],
    _requestBodyLength: 0,
    _requestBodyBuffers: [],
    _onNativeResponse: [Function (anonymous)],
    _currentRequest: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [Socket],
      _header: 'GET /finance/quote/ETH-USD HTTP/1.1\r\n' +        
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/1.4.0\r\n' +
        'Accept-Encoding: gzip, compress, deflate, br\r\n' +      
        'Host: www.google.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/finance/quote/ETH-USD',
      _ended: false,
      res: null,
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'www.google.com',
      protocol: 'http:',
      _redirectable: [Circular *1],
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kUniqueHeaders)]: null
    },
    _currentUrl: 'http://www.google.com/finance/quote/ETH-USD',  
    [Symbol(kCapture)]: false
  },
  cause: Error: connect ETIMEDOUT 2XXX:XXXX:XXXX:808::2004:80    
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
    errno: -4039,
    code: 'ETIMEDOUT',
    syscall: 'connect',
    address: '2XXX:XXXX:XXXX:808::2004',
    port: 80
  }
}

我非常感谢任何帮助

JavaScript 节点.js ajax axios google-finance-api

评论

1赞 derpirscher 7/21/2023
你真的在称它为不安全的连接吗?但这可能不是原因。超时可能有很多原因,例如网络连接或防火墙设置,...例如,您可以在浏览器或 Postman 中打开相同的 url 吗?您可以使用节点请求其他 url 吗?http://...
0赞 yakob 7/21/2023
你好。对不起。当然,我正在向 https 发出请求。我刚刚做了很多实验,这就是为什么你现在在我的代码中看到 http 的原因。所以这不是一个理由。是的,我可以在浏览器中打开此网址,我在 Postman 中也得到了 OK 响应。我检查了这个api(“jsonplaceholder.typicode.com/posts/1”),我成功地得到了节点的响应
1赞 van le 10/25/2023
嗨,@yakob,你解决了问题吗?我也面临这个问题
0赞 yakob 10/27/2023
嗨@van le No.一点也不。这个问题不仅在 Axios 中是可重现的,甚至在 fetch 方法中也是可重现的。问题似乎与笔记本电脑网络设置有关。我不知道如何解决它,看起来没有人知道))
0赞 yakob 12/17/2023
@vanle 问题解决了。这是我的互联网提供商的错

答:

0赞 yakob 12/17/2023 #1

问题解决了。这是我的互联网提供商的错

评论

0赞 Marco 12/20/2023
虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接的页面发生更改,仅链接的答案可能会失效。- 从评论