bogdan_uman
@bogdan_uman
шлЫмазл неукЪ-поцЪ

Axios не работает proxy?

Здравствуйте. Подскажите пожалуйста. Использую axios 18.01 и Node.js . И почему-то не работает proxy?
Прокси рабочий, puppeteer грузит страничку.

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
}


Спасибо.
  • Вопрос задан
  • 1933 просмотра
Решения вопроса 1
@grinat
Я в свое время чтобы заставить работать axios через прокси, ставил отдельный пакет, axios-proxy что-то в этом духе, у них в гитхабе есть ишью с какой-то ошибкой в прокси, и там ссылка на этот пакет. Да и аксиос под нодой полное дерьмо, рекомендую использовать request.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
summer Ярославль
от 100 000 до 140 000 ₽
КРАФТТЕК Санкт-Петербург
от 60 000 до 80 000 ₽
20 апр. 2024, в 09:15
8000 руб./за проект
20 апр. 2024, в 08:39
100000 руб./за проект
20 апр. 2024, в 08:24
1500 руб./за проект