sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Request Error: Unable to verify the first certificate #675

Closed jamigibbs closed 5 years ago

jamigibbs commented 5 years ago

Describe the bug

A ran into the following error and I'm not sure what's causing it. I think issue #208 is the closest to what it could be related to but I'm assuming, since I'm using the latest version, this shouldn't be an issue any longer. Could it be that the host in question hasn't properly configured their SSL cert?

  name: 'RequestError',
  code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
  host: 'store.chicagotribune.com',
  hostname: 'store.chicagotribune.com',
  method: 'GET',
  path: '/product/7QAMCT250/chicago-tribune-commemorative-date-book',
  socketPath: undefined,
  protocol: 'https:',
  url:

Actual behavior

The requested url is returning a request error

{ RequestError: unable to verify the first certificate
    at ClientRequest.request.once.error (/.../node_modules/got/source/request-as-event-emitter.js:165:14)
    at Object.onceWrapper (events.js:273:13)
    at ClientRequest.emit (events.js:187:15)
    at ClientRequest.origin.emit.args [as emit] (/.../node_modules/@szmarczak/http-timer/source/index.js:36:11)
    at TLSSocket.socketErrorListener (_http_client.js:382:9)
    at TLSSocket.emit (events.js:182:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Expected behavior

The requested url returns expected data and not an error.

Code to reproduce

const metascraper = require('metascraper')([
  require('metascraper-title')(),
  require('metascraper-url')(),
  require('metascraper-image')()
])

const got = require('got')

const metadata = async function(targetUrl){
  try {
    const { body: html, url } = await got(targetUrl)
    const metadata = await metascraper({ html, url })
    return metadata
  } catch(err) { console.log(err) }
}

module.exports = metadata

Checklist

sindresorhus commented 5 years ago

Could it be that the host in question hasn't properly configured their SSL cert?

Yes, it means the certificate is somehow invalid. You can set the {rejectUnauthorized: false} option to ignore such errors, but I would not recommend that.

Mohhay commented 5 years ago

How do i do that? Please help me, ive been stuck with this stupid UNABLE_TO_VERIFY_LEAF_SIGNATURE problem, could you help me? Cause im mad at myself, ive been trying to solve this in 3 days, and ive not completed solving it. Im trying to make a discord.js bot, but i can't. :( Please help

jamigibbs commented 5 years ago

@Mohhay There is an options argument that you can pass settings into although it doesn't look like this setting is documented in the readme. For example:

got(targetUrl, {rejectUnauthorized: false})

Mohhay commented 5 years ago

Could you please tell me how to do this options thing, btw thanks for the answer, im mad cause of this bug. Please do a tutorial by steps like, 1. Go to ….. 2. Type…. If you could do that, it would be very appriciated.

szmarczak commented 5 years ago

@jamigibbs has already answered you with the correct solution.

Mohhay commented 5 years ago

Yeah i know, but im new at node.js i don't know how to fix this setting, i don't undertsand, make it more clear what i should do.

szmarczak commented 5 years ago

The answer is at its clearest state - it's not possible to simplify it.

So you're just getting started with coding. Coding professional stuff at start is hard. Here we deal only with Got-specific problems, so please don't make issues not related to Got. For beginners I recommend the MDN Guide.

Mohhay commented 5 years ago

You know, i can’t even code if i can’t fix this problem, it prevents me from Everything, so please guide me to fix it, idk why this problem decided to happen with me, but i hate myself.

Skickades från E-post för Windows 10

Från: Szymon Marczak Skickat: den 10 april 2019 20:50 Till: sindresorhus/got Kopia: Mohhay; Mention Ämne: Re: [sindresorhus/got] Request Error: Unable to verify the firstcertificate (#675)

The answer is at its clearest state - it's not possible to simplify it. So you're just getting started with coding. Coding professional stuff at start is hard. Here we deal only with Got-specific problems, so please don't make issues not related to Got. For beginners I recommend the MDN Guide. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

szmarczak commented 5 years ago

Sorry, I can't help you further :confused: This is not an introduction to programming.

Mohhay commented 5 years ago

Well, tbh, its saying that stupid thing every second i type in npm, How should i do anything with that? Im mad because of it,

Skickades från E-post för Windows 10

Från: Szymon Marczak Skickat: den 10 april 2019 21:22 Till: sindresorhus/got Kopia: Mohhay; Mention Ämne: Re: [sindresorhus/got] Request Error: Unable to verify the firstcertificate (#675)

Sorry, I can't help you further 😕 This is not an introduction to programming. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

atulrawat85 commented 3 years ago

One line solution, https://learninghub.guru blogs article resolved my issue, please refer Link

Their Fantastic Blog's Android App: Link

Shivamk1byjus commented 3 years ago

I am also getting the same error, but when hitting with postman the same host I am able to get the response. Can you please tell why postman is not getting such issue.