plainheart / bing-translate-api

A simple and free API for Bing & Microsoft Translator for Node.js
https://github.com/plainheart/bing-translate-api
MIT License
156 stars 28 forks source link

failed to fetch IG and IID RequestError: read ECONNRESET #1

Closed flyeven closed 3 years ago

flyeven commented 3 years ago

是不是匿名已经无法使用了呢?

failed to fetch IG and IID RequestError: read ECONNRESET
    at ClientRequest.<anonymous> (D:\Programming\nodescraping\node_modules\bing-translate-api\node_modules\got\dist\source\core\index.js:956:111)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:327:22)
    at ClientRequest.origin.emit (D:\Programming\nodescraping\node_modules\bing-translate-api\node_modules\@szmarczak\http-timer\dist\source\index.js:39:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
  code: 'ECONNRESET',
  timings: {
    start: 1615619504845,
    socket: 1615619504845,
    lookup: 1615619504869,
    connect: 1615619507828,
    secureConnect: undefined,
    upload: undefined,
    response: undefined,
    end: undefined,
    error: 1615619510679,
    abort: undefined,
    phases: {
      wait: 0,
      dns: 24,
      tcp: 2959,
      tls: undefined,
      request: undefined,
      firstByte: undefined,
      download: undefined,
      total: 5834
    }
  }
}

RequestError: read ECONNRESET
    at ClientRequest.<anonymous> (D:\Programming\nodescraping\node_modules\bing-translate-api\node_modules\got\dist\source\core\index.js:956:111)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:327:22)
    at ClientRequest.origin.emit (D:\Programming\nodescraping\node_modules\bing-translate-api\node_modules\@szmarczak\http-timer\dist\source\index.js:39:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
  code: 'ECONNRESET',
  timings: {
    start: 1615619504875,
    socket: 1615619504875,
    lookup: 1615619504875,
    connect: 1615619507827,
    secureConnect: undefined,
    upload: undefined,
    response: undefined,
    end: undefined,
    error: 1615619510694,
    abort: undefined,
    phases: {
      wait: 0,
      dns: 0,
      tcp: 2952,
      tls: undefined,
      request: undefined,
      firstByte: undefined,
      download: undefined,
      total: 5819
    }
  }
}
RequestError: read ECONNRESET
    at ClientRequest.<anonymous> (D:\Programming\nodescraping\node_modules\bing-translate-api\node_modules\got\dist\source\core\index.js:956:111)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:327:22)
    at ClientRequest.origin.emit (D:\Programming\nodescraping\node_modules\bing-translate-api\node_modules\@szmarczak\http-timer\dist\source\index.js:39:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
  code: 'ECONNRESET',
  timings: {
    start: 1615619504858,
    socket: 1615619504858,
    lookup: 1615619504870,
    connect: 1615619507828,
    secureConnect: undefined,
    upload: undefined,
    response: undefined,
    end: undefined,
    error: 1615619510697,
    abort: undefined,
    phases: {
      wait: 0,
      dns: 12,
      tcp: 2958,
      tls: undefined,
      request: undefined,
      firstByte: undefined,
      download: undefined,
      total: 5839
    }
  }
}
plainheart commented 3 years ago

Hi, 是否是临时的网络问题?我刚刚运行了测试用例,结果显示并无异常。

flyeven commented 3 years ago

我也测了下,只运行测试代码正常。可能是并发大量翻译造成的。

使用 google translate api 也有类似问题。单个测试大概能过。大量请求基本都是 RequestError 。看来还要想办法注册key。

另外,刚才测试中出现 translate is not a function 错误。

改为 import { translate as trans_bing } from 'bing-translate-api'; 用 trans_bing 就没错了。遇到过这种问题吗?

下面是 google translation 的错误信息。

GotError [RequestError]: socket hang up
    at ClientRequest.<anonymous> (D:\Programming\nodescraping\node_modules\got\source\request-as-event-emitter.js:178:14)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:327:22)
    at ClientRequest.origin.emit (D:\Programming\nodescraping\node_modules\@szmarczak\http-timer\source\index.js:37:11)
    at TLSSocket.socketOnEnd (_http_client.js:493:9)
    at TLSSocket.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'ECONNRESET',
  host: 'translate.google.com',
  hostname: 'translate.google.com',
  method: 'GET',
  path: '/',
  socketPath: undefined,
  protocol: 'https:',
  url: 'https://translate.google.com/',
  gotOptions: {
    path: '/',
    protocol: 'https:',
    slashes: true,
    auth: null,
    host: 'translate.google.com',
    port: null,
    hostname: 'translate.google.com',
    hash: null,
    search: null,
    query: null,
    pathname: '/',
    href: 'https://translate.google.com/',
    retry: {
      retries: [Function (anonymous)],
      methods: [Set],
      statusCodes: [Set],
      errorCodes: [Set]
    },
    headers: {
      'user-agent': 'got/9.6.0 (https://github.com/sindresorhus/got)',
      'accept-encoding': 'gzip, deflate'
    },
    hooks: {
      beforeRequest: [],
      beforeRedirect: [],
      beforeRetry: [],
      afterResponse: [],
      beforeError: [],
      init: []
    },
    decompress: true,
    throwHttpErrors: true,
    followRedirect: true,
    stream: false,
    form: false,
    json: false,
    cache: false,
    useElectronNet: false,
    agent: TunnelingAgent {
      options: [Object],
      proxyOptions: [Object],
      maxSockets: Infinity,
      requests: [],
      sockets: [Array],
      _events: [Object: null prototype],
      _eventsCount: 1,
      request: [Function: request],
      createSocket: [Function: createSecureSocket],
      defaultPort: 443
    },
    method: 'GET',
    forceRefresh: true
  }
}
plainheart commented 3 years ago

另外,刚才测试中出现 translate is not a function 错误。 改为 import { translate as trans_bing } from 'bing-translate-api'; 用 trans_bing 就没错了。遇到过这种问题吗?

暂时没有遇到,也许是其他地方声明了同名变量被覆盖了。

大量并发的情况还没有测试过,不过毕竟是 free to use, 还是建议控制请求频率。