B
B
Bogdan2019-11-13 21:24:27
JavaScript
Bogdan, 2019-11-13 21:24:27

Axios proxy not working?

Hello. Tell me please. I'm using axios 18.01 and Node.js . And for some reason the proxy does not work?
The proxy is working, puppeteer is loading the page.

try {
      await axios({
        url: 'https://api.ipify.org/',
       proxy: { host: '182.53.206.138', port: '8080' },
        timeout: process.env.PROXY_CHECK_TIMEOUT * 1000
      });
    } catch (err) {
      console.log(`${err.code} | ${err.message}`);
    }
  }

ECONNABORTED | timeout of 10000ms exceeded
Error: timeout of 10000ms exceeded
    at createError (/home/user/Project/usr-info/node_modules/axios/lib/core/createError.js:16:15)
    at Timeout.handleRequestTimeout [as _onTimeout] (/home/user/Project/usr-info/node_modules/axios/lib/adapters/http.js:217:16)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7) {
  config: {
    adapter: [Function: httpAdapter],
    transformRequest: { '0': [Function: transformRequest] },
    transformResponse: { '0': [Function: transformResponse] },
    timeout: 10000,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    validateStatus: [Function: validateStatus],
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.18.1',
Error: INVALID_PROXY
    at Function.check (/home/user/Project/usr-info/services/proxy.js:37:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
      host: 'api.ipify.org'
    },
    method: 'get',
    url: 'https://api.ipify.org/',
    proxy: { host: '182.53.206.138', port: '8080', protocol: 'http' },
    data: undefined
  },
  code: 'ECONNABORTED',
  request: 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,
      bufferedRequest: null,
      lastBufferedRequest: null,
      pendingcb: 0,
      prefinished: false,
      errorEmitted: false,
      emitClose: true,
      autoDestroy: false,
      bufferedRequestCount: 0,
      corkedRequestsFree: [Object]
    },
    writable: true,
    _events: [Object: null prototype] {
      response: [Function: handleResponse],
      error: [Function: handleRequestError]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    _options: {
      protocol: 'https:',
      maxRedirects: 21,
      maxBodyLength: 10485760,
      path: 'https://api.ipify.org/',
      method: 'get',
      headers: [Object],
      agent: undefined,
      auth: undefined,
      hostname: '182.53.206.138',
      port: '8080',
      nativeProtocols: [Object],
      pathname: 'https://api.ipify.org/'
    },
    _redirectCount: 0,
    _redirects: [],
    _requestBodyLength: 0,
    _requestBodyBuffers: [],
    _onNativeResponse: [Function],
    _currentRequest: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      connection: [TLSSocket],
      _header: 'GET https://api.ipify.org/ HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/0.18.1\r\n' +
        'host: api.ipify.org\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      path: 'https://api.ipify.org/',
      _ended: false,
      res: null,
      aborted: true,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: [HTTPParser],
      maxHeadersCount: null,
      _redirectable: [Circular],
      [Symbol(kNeedDrain)]: false,
      [Symbol(isCorked)]: false,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    _currentUrl: 'https://182.53.206.138:8080/https://api.ipify.org/'
  },
  response: undefined
}

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2019-11-13
@bogdan_uman

At one time, in order to make axios work through a proxy, I installed a separate package, axios-proxy something like that, they have an issue in the github with some kind of error in the proxy, and there is a link to this package. Yes, and the axios under the node is complete shit, I recommend using request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question