Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy error #10

Closed
tockawaffle opened this issue May 16, 2023 · 5 comments
Closed

Proxy error #10

tockawaffle opened this issue May 16, 2023 · 5 comments

Comments

@tockawaffle
Copy link

tockawaffle commented May 16, 2023

Hello!

I recently encountered an issue while using proxies, specifically with Axios. I'm fairly confident that I've set up my proxy correctly, but I'm unsure if the problem lies with Axios itself or if there's a misconfiguration with my proxy.

The issue arose when using the default settings:

const agent = new https.Agent({
            rejectUnauthorized: false,
        });
        let axiosOptions = {
            proxy: this.options.proxy,
            httpsAgent: agent,
            headers: {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0",
                Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
                "Accept-Language": "en-US,en;q=0.5",
                "Accept-Encoding": "gzip, deflate, br",
                Connection: "keep-alive",
                "Upgrade-Insecure-Requests": "1",
                "Sec-Fetch-Dest": "document",
                "Sec-Fetch-Mode": "navigate",
                "Sec-Fetch-Site": "none",
                "Sec-Fetch-User": "?1",
                TE: "trailers",
            },
        };

With these settings, I received a 502 error, which stated "The requested URL could not be retrieved". This issue seemed to occur when using a Squid proxy.

To rectify this problem, I implemented the following steps:

  • 1: I used the HttpsProxyAgent() from the https-proxy-agent module.
  • 2: I removed the proxy setting.
  • 3: I set the httpsAgent with the HttpsProxyAgent.

Here's an example of the changes I made:

import HttpsProxyAgent from "https-proxy-agent";
let axiosOptions = {
          proxy: false,
          httpsAgent: new HttpsProxyAgent(`http://user:password@ip:port`),
          headers: {
              "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0",
              Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
              "Accept-Language": "en-US,en;q=0.5",
              "Accept-Encoding": "gzip, deflate, br",
              Connection: "keep-alive",
              "Upgrade-Insecure-Requests": "1",
              "Sec-Fetch-Dest": "document",
              "Sec-Fetch-Mode": "navigate",
              "Sec-Fetch-Site": "none",
              "Sec-Fetch-User": "?1",
              TE: "trailers",
          },
};

I suspect the issue may be a bug with Axios, possibly related to its handling of proxying HTTP to HTTPS. Alternatively, it might be a configuration issue with the Squid proxy. I thought it would be worth raising this issue to bring it to attention.

@PawanOsman
Copy link
Owner

can you show us an example of how you used the proxy settings?

@tockawaffle
Copy link
Author

tockawaffle commented May 19, 2023

I was using the proxy setting on the package as described in the readme:

import { Bard } from "googlebard";

export default async function orchestra() {
    const importDynamic = new Function(
        "modulePath",
        "return import(modulePath)"
    );
    const { Bard } = await importDynamic("googlebard");
    const choirs = new Bard(`__Secure-1PSID="${process.env.BARD_COOKIE!}"`, {
        proxy: {
            host: process.env.BARD_PROXY_HOST!,
            port: process.env.BARD_PROXY_PORT!,
            auth: {
                username: process.env.BARD_PROXY_USERNAME!,
                password: process.env.BARD_PROXY_PASSWORD!,
            },
            protocol: "http",
        },
    });
    return choirs as Bard;
}

That would throw the default error of the package, asking to check the cookie that was set, but with some digging and logging I could find the actual error:
AxiosError: Request failed with status code 502
With the Squid info below it:

</head><body id=ERR_READ_ERROR>\n' +
      '<div id="titles">\n' +
      '<h1>ERROR</h1>\n' +
      '<h2>The requested URL could not be retrieved</h2>\n' +
      '</div>\n' +
      '<hr>\n' +
      '\n' +
      '<div id="content">\n' +
      '<p>The following error was encountered while trying to retrieve the URL: <a href="https://bard.google.com/">https://bard.google.com/</a></p>\n' +
      '\n' +
      '<blockquote id="error">\n' +
      '<p><b>Read Error</b></p>\n' +
      '</blockquote>\n' +
      '\n' +
      '<p id="sysmsg">The system returned: <i>[No Error]</i></p>\n' +
      '\n' +
      '<p>An error condition occurred while reading data from the network. Please retry your request.</p>\n' +

The proxy is being used with the default configuration, I can see it on the proxy object on the error thrown: AxiosError.log

The solution I found was to use:

import HttpsProxyAgent from "https-proxy-agent";
let axiosOptions = {
          proxy: false,
          httpsAgent: new HttpsProxyAgent(`http://user:password@ip:port`),
          headers: {
              "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0",
              Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
              "Accept-Language": "en-US,en;q=0.5",
              "Accept-Encoding": "gzip, deflate, br",
              Connection: "keep-alive",
              "Upgrade-Insecure-Requests": "1",
              "Sec-Fetch-Dest": "document",
              "Sec-Fetch-Mode": "navigate",
              "Sec-Fetch-Site": "none",
              "Sec-Fetch-User": "?1",
              TE: "trailers",
          },
};

This error is being thrown at the GetRequestParams() function, this might be an Axios error, look here

Since I changed it directly on the package's code, I didn't do any additional configuration on my end, only changed that part of the code and used it.
Also, I'm not sure if this would impact someone else since most people would use a public proxy and not a private one, so you can close this issue if you find that it woudn't impact most users.

@PawanOsman
Copy link
Owner

Thank you, can you confirm that the proxy protocol you used is http? maybe its https and you need to set the protocol to https

@tockawaffle
Copy link
Author

Nope, my proxy is http.
When I try using it with https, this gets thrown:

cause: Error: write EPROTO 984C0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:
  
      at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16) {
    errno: -4046,
    code: 'EPROTO',
    syscall: 'write'
  }

@tockawaffle
Copy link
Author

Since it's not an error caused by this package itself, and I just wanted to document for further references, I'll close this issue.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants