talmobi/tor-request

promise for request body

KingMatrix1989 opened this issue · 3 comments

Hi. i need to await request body in my scrapping project. so i have implemented this function:

const TorGet = async (url) => {
  return new Promise(function(resolve, reject) {
    tr.request(url, async (err, res, body) => {
      if (err) {
        reject(err);
      }
      else resolve({ data: body });
    });
  })
}

When i iterate this function on a async loop, at 2nd call it seems request changes the ip.

Where is problem?

The most commons ways for tor to connect to another endpoint node ( get a new IP ) is when 1) tor is restarted 2) you request a new session using the control port 3) "randomly" by tor itself ( it can do this from time to time ).

What might be happening here is that tor itself is crashing during your loop somehow? Maybe you are spawning the tor binary as a child process ( which I would not recommend, although haven't put much thought into this right now ).

Try this code...please let us know if it works or not as soon as you can, thanks!

const TorGet = async(url) => {
  return new Promise((resolve, reject) => {
    tr.request(url, async, (err, res, body) => {
        return err ? reject(err) : resolve({ data: body })
    })
  })
}

Closing as this issue is not related to the tor-request itself.