Http proxy problem

I added in n8n.env

HTTP_PROXY="http://10.20.0.1:1080"
HTTPS_PROXY="http://10.20.0.1:1080"

And everything worked successfully, until the latest version was updated.
When I start Workflow, I get a 400 Bad Request error.

StackTrace
ERROR RESPONSE
NodeApiError: Bad request - please check your parameters
    at Object.apiRequest (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Telegram/GenericFunctions.js:84:15)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Object.checkExists (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Telegram/TelegramTrigger.node.js:148:47)
    at async ActiveWorkflowRunner.addWorkflowWebhooks (/usr/local/lib/node_modules/n8n/dist/src/ActiveWorkflowRunner.js:205:39)
    at async ActiveWorkflowRunner.add (/usr/local/lib/node_modules/n8n/dist/src/ActiveWorkflowRunner.js:349:13)
    at async /usr/local/lib/node_modules/n8n/dist/src/Server.js:471:21
    at async /usr/local/lib/node_modules/n8n/dist/src/ResponseHelper.js:86:26 {
  cause: Error: Request failed with status code 400
      at createError (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/createError.js:16:15)
      at settle (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/settle.js:17:12)
      at IncomingMessage.handleStreamEnd (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/adapters/http.js:269:11)
      at IncomingMessage.emit (events.js:327:22)
      at IncomingMessage.EventEmitter.emit (domain.js:467:12)
      at endReadableNT (internal/streams/readable.js:1327:12)
      at processTicksAndRejections (internal/process/task_queues.js:80:21) {
    config: undefined,
    request: undefined,
    response: {
      status: 400,
      statusText: 'Bad Request',
      headers: [Object],
      config: [Object],
      request: [ClientRequest],
      data: '<html><head><title>400 Bad Request</title></head>\r\n' +
        '<body><h2>400 Bad Request</h2></body></html>\r\n'
    },
    isAxiosError: true,
    toJSON: [Function: toJSON],
    cause: {},
    error: '<html><head><title>400 Bad Request</title></head>\r\n' +
      '<body><h2>400 Bad Request</h2></body></html>\r\n',
    statusCode: 400,
    options: {
      url: 'https://api.telegram.org/botTOKEN/getWebhookInfo',
      method: 'post',
      headers: [Object],
      transformRequest: undefined,
      transformResponse: undefined,
      paramsSerializer: undefined,
      timeout: 300000,
      adapter: undefined,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: undefined,
      transitional: [Object],
      'axios-retry': [Object],
      data: undefined,
      httpsAgent: undefined
    }
  },
  node: {
    parameters: { updates: [Array], additionalFields: [Object] },
    name: 'TG WebHook',
    type: 'n8n-nodes-base.telegramTrigger',
    typeVersion: 1,
    position: [ 170, 500 ],
    webhookId: 'ID',
    credentials: { telegramApi: [Object] }
  },
  timestamp: 1635701784120,
  httpCode: '400',
  description: '<html><head><title>400 Bad Request</title></head>\r\n' +
    '<body><h2>400 Bad Request</h2></body></html>\r\n'

The same request on the same server through curl + proxy succeeds.
Also, when there is an error in the service, I can see the request in the proxy log.

Version: 0.146.0

We change the library to make http requests from request to axios. That env variable HTTP_PROXY and HTTPS_PROXY are only valid for the request library and not axios. To keep using the request library set the env variable N8N_USE_DEPRECATED_REQUEST_LIB=true

yeah the new library is breaking lots of things for me, using HTTP request nodes, I’m going to have to go back to the old library.

Why haven’t you updated this document? n8n/BREAKING-CHANGES.md at master · n8n-io/n8n · GitHub

The new library will not support HTTP RPOXY?

When will support for N8N_USE_DEPRECATED_REQUEST_LIB be removed ?

Because we do not support the env variables that an underline library uses, we only offer support for the env variable in our docs.

I guess there is an equivalent in Axios to do so using the env variables. However, why are you using env variables in the first place and not the poxy parameter in the HTTP node? What Am I missing?

I am not sure, but I will say that until the migration to Axios is stable enough, and we have fixed all the issues that arose.

It will help if you share the issues you are having so that we can fix them.

All requests must go through a proxy, because there is no internet on the server.

It is expensive to configure in each HTTP node, besides, how can I configure proxy for Telegram Trigger, Trello Triger?

these have been logged in other tickets. :wink:

having a universal proxy toggle would be handy :wink:

Ahh, I see how setting a global proxy is useful for your use-case. According to the docs, with Axios you should be able to do the same setting the env variable https_proxy and https_proxy

1 Like

I set http_proxy and https_proxy in the .env file, the error remains the same.
What am I doing wrong?

I assigned this to one of my coworkers that have a better insight.

Hello everyone.

I just tested using the environment variables mentioned http_proxy and https_proxy and it works fine.

I even hacked Axios’ source code to output a message whenever it was checking for proxy operation and it worked. Axios follows these environment variables exactly like the request library used to do.

So, my setup:

  • squid running locally on port 3128
  • n8n workflow using http request node, making a basic GET request to any web page
  • no proxy set manually for http request node
  • I am “watching” for squid’s access log file changes, and I can see the requests being proxied via squid correctly.

I attached some screenshots of the setup:

Screenshot from 2021-11-08 14-17-32

This is Squid’s access log:

Which leads me to believe the problem is not with the proxy itself.

Could you please try running this locally on a setup that does not require proxy (could be your local machine) so we can try to pinpoint what’s the problem? Maybe it’s something else related to the request, like Content-type, body or something else.