not-an-aardvark / snoowrap

A JavaScript wrapper for the reddit API
MIT License
1.01k stars 125 forks source link

RequestError: Error: getaddrinfo ENOTFOUND oauth.reddit.com #295

Closed ExperiBass closed 3 years ago

ExperiBass commented 3 years ago

Dunno why this happens, my bot still works even with this oddly

RequestError: Error: getaddrinfo ENOTFOUND oauth.reddit.com
    at new RequestError (/Users/gingkathfox/Documents/GitHub/Random/TrapMonitor/node_modules/request-promise-core/lib/errors.js:14:15)
    at Request.plumbing.callback (/Users/gingkathfox/Documents/GitHub/Random/TrapMonitor/node_modules/request-promise-core/lib/plumbing.js:87:29)
    at Request.RP$callback [as _callback] (/Users/gingkathfox/Documents/GitHub/Random/TrapMonitor/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at self.callback (/Users/gingkathfox/Documents/GitHub/Random/TrapMonitor/node_modules/request/request.js:185:22)
    at Request.emit (node:events:376:20)
    at Request.onRequestError (/Users/gingkathfox/Documents/GitHub/Random/TrapMonitor/node_modules/request/request.js:877:8)
    at ClientRequest.emit (node:events:388:22)
    at TLSSocket.socketErrorListener (node:_http_client:486:9)
    at TLSSocket.emit (node:events:376:20)
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)
Venefilyn commented 3 years ago

Checked on Reddit for PRAW, but might be applicable here as well

This means your script can't resolve hostname to an IP address. Test the script on another environment or contact your network administrator.

If you can't get it to work, can you create small reproducible code?

ExperiBass commented 3 years ago

it appears to be reddit specifically, ive tried my discord bot and ESI, both work perfectly with no ENOTFOUND. heres the code:

let snoowrap = require('snoowrap')
let snoostorm = require('snoostorm')
let fs = require('fs')

const r = new snoowrap({
    userAgent: 'X',
    clientId: 'A',
    clientSecret: 'B',
    refresh_token: 'C'
})
let usages = JSON.parse(fs.readFileSync(`./usages.json`, 'utf8'))
let posts = new snoostorm.SubmissionStream(r, {
    subreddit: `GoodAnimemes`,
    limit: 0,
    pollTime: 2000
})
let comments = new snoostorm.CommentStream(r, {
    subreddit: `GoodAnimemes`,
    limit: 0,
    pollTime: 2000
})
posts.on(`item`, post => {
    // if the post title has the word trap and the body doesnt, then save
    if (post.title.includes("trap") && !post.selftext.includes("trap")) {
        const data = {
            title: post.title,
            author: post.author.name,
            url: post.url
        }
        usages.usages.push(data)
        console.log(`Usage detected!`)
    }
    // if the body has the word trap, save (this catches posts that have the body and title both with the word trap)
    if (post.selftext && post.selftext.includes("trap")) {
        const data = {
            selftext: post.selftext,
            author: post.author.name,
            url: post.url
        }
        usages.usages.push(data)
        console.log(`Usage detected!`)
    }
})
comments.on('item', comment => {
    if (comment.body.includes("trap")) {
        const data = {
            comment: comment.body,
            author: comment.author.name,
            url: `https://reddit.com${comment.permalink}`
        }
        usages.usages.push(data)
        console.log(`Usage detected!`)
    }
})

process.on('SIGINT', () => {
    console.log(`Writing file...`)
    fs.writeFileSync(`./usages.json`, JSON.stringify(usages, null, 4))
    process.exit()
})
process.on('unhandledRejection', (e) => {
    console.error(e.stack)
})
process.on('uncaughtException', (e) => {
    console.error(e.stack)
})
Venefilyn commented 3 years ago

I see, most likely Reddit hiccup then. Once we migrate away from request dependency we should at least get a better error when this happens

ExperiBass commented 3 years ago

cool, thanks :D