question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios Proxy Issues - 501 and SSL errors

See original GitHub issue

Describe the bug

Getting weird error messages when passing a proxy into an Axios request. I’ve tried to add a proxy parameter to the following GET request and I get a 501 error code and when I then add a protocol parameter to the proxy object I get an openssl error

Note that I don’t have any of these issues when using the library axios-https-proxy-fix, https://www.npmjs.com/package/axios-https-proxy-fix

To Reproduce

axios
    .get(prod, {
        proxy: {
            host: proxy.host,
            port: proxy.port,
            auth: {
                username: proxy.userName,
                password: proxy.password,
            },
        }
    })

Then I tried adding protocol to the proxy object, like so:

axios
    .get(prod, {
        proxy: {
            protocol: "https",
            host: proxy.host,
            port: proxy.port,
            auth: {
                username: proxy.userName,
                password: proxy.password,
            },
        }
    })

Error:

write EPROTO 17828:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:

Expected behavior

No 501 and no openssl issues. Should get a 200 response.

Environment

  • Axios Version 0.21.0
  • Node.js Version 12.17
  • OS: Windows 10

Additional context/Screenshots

N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:29
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
saamalikcommented, Jan 23, 2021

Until a proper fix is implemented in the library, here is the workaround I used:

import HttpsProxyAgent from 'https-proxy-agent'
    this.client = axios.create({
      baseURL: `https://${this.host}`,
      httpsAgent: new HttpsProxyAgent(process.env.HTTPS_PROXY),
      proxy: false,
      ....
    });

Note that proxy must be set to false otherwise the adapter will try to initialize it again from the environment variable.

For a complete example (with proxy and no proxy): https://github.com/spectrocloud/k8s-set-context/blob/690044f1c02048af0e4b7470dd70306ef1f4556b/src/client.ts#L36-L54

8reactions
cs17sss2commented, Jan 3, 2021

Not working for me either, please fix

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use axios to make an https call? - Stack Overflow
Axios https proxy support is borked if using https proxies. Try passing the proxy through httpsProxyAgent using http.
Read more >
How to Fix the HTTP 501 Not Implemented Error on Your Site
The HTTP 501 Not Implemented status code indicates that the server does not support the functionality required to fulfill the request.
Read more >
501 Not Implemented - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 501 Not Implemented server error response code means that the server does not support the ...
Read more >
ssl wrong version number | The Search Engine You Control
This line seems to be the problem: ssl_version=ssl.PROTOCOL_TLSv1 . ... It seems both stages need to have access of the proxy envs.
Read more >
503 Service Unavailable Error: What It Is and How to Fix It
A close look at what a 503 Service Unavailable Error is, including troubleshooting tips to help you resolve this error in your own ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found