0

I'm trying to use a HTTP proxy file, choosing a random proxy for each request, then requesting using the request-promise library.

const rp = require('request-promise'),
    fs = require('fs')

var proxies = []

function sendR() {
    let proxy = getProxy()
    console.log('Got proxy ' + proxy)
    let requestThing = rp.defaults({
        method: 'GET',
        proxy: 'http://' + proxy
    })
    requestThing('http://server.test.ip:1234').then((body) => {
        console.log(body)
    })
}

function getProxy() {
    return proxies[Math.floor(Math.random() * proxies.length)]
}

fs.readFile('proxy.txt', (err, data) => {
    if (err) throw err
    proxies = data.toString().split("\n")
})

setTimeout(sendR, 1000)

I'm getting the error Unhandled rejection RequestError: Error: connect ETIMEDOUT 1.1.1.1:80, and I've checked all proxies very frequently.

Cooper
  • 47
  • 2
  • 10

1 Answers1

0

Just continuing to test worked. Doing this fixed it.

const rp = require('request-promise'),
    fs = require('fs')

var proxies = []

function sendR() {
    let proxy = getProxy()
    console.log('Got proxy ' + proxy)
    let requestThing = rp.defaults({
        method: 'GET',
        proxy: 'http://' + proxy,
        jar: true
    })
    requestThing('http://a').then((body) => {
        console.log(body)
    }).catch((e) => {
        console.log('Error with proxy ' + proxy)
    })
}

function getProxy() {
    return proxies[Math.floor(Math.random() * proxies.length)]
}

fs.readFile('proxy.txt', (err, data) => {
    if (err) throw err
    proxies = data.toString().split("\n")
})

setTimeout(() => {
    setInterval(sendR, 50)
}, 1000)

I guess the issue was the proxies, as testing a lot of them eventually went through. My mistake. https://i.stack.imgur.com/7vooX.png

Cooper
  • 47
  • 2
  • 10