codemanki / cloudscraper

--DEPRECATED -- 🛑 🛑 Node.js library to bypass cloudflare's anti-ddos page
MIT License
603 stars 141 forks source link

Error: tunneling socket could not be established #236

Closed dpalade06 closed 5 years ago

dpalade06 commented 5 years ago

I've been trying to use this library to send get requests to CloudFlare protected websites using some http / https proxies.

For some reason I keep getting errors like:

What exactly am I doing wrong?


var options = {
    uri: args['url'],
    jar: request.jar(),
    proxy: 'http://' + s_proxy,
    headers: {
        'Connection': 'keep-alive',
        'User-Agent': uas[Math.floor(Math.random() * uas.length)],
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'en-US,en;q=0.9'
    },
    cloudflareTimeout: 5000,
    cloudflareMaxTimeout: 6000,
    followAllRedirects: true,
    challengesToSolve: 3,
    decodeEmails: false,
    gzip: true,
    agentOptions: { ciphers }
};

cloudscraper.get(args['url'] , function (error, response, body) {

    if (error) {
        throw error;
    }

    console.log("[+] Request has been sent. (" + s_proxy + ")");

});

I even tried setting the proxy env variables, but no luck.

ghost commented 5 years ago

Hi @dpalade06,

The proxies are the problem 90% of the time. For example:

RequestError: Error: tunneling socket could not be established, statusCode=503

Looks like the proxy server hung up because of Cloudflare's response status code. Either way, it's a server error code. The problem is on their end.

Have a look at https://github.com/codemanki/cloudscraper/issues/233#issuecomment-510342262 for an example and tests.

Cheers

ghost commented 5 years ago

https://github.com/codemanki/cloudscraper/issues/234