Normandie Dev
Normandie Dev

Reputation: 13

PHP API - SSL certificate problem in localhost

I work locally on Wampserver and I want to access an API locally.

It gives me this error:

( ! ) Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.themoviedb.org/3/movie/now_playing?language=fr-FR&page=1&region=FR in C:\wamp64\www\sites\mon-site\library\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 211
( ! ) GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.themoviedb.org/3/movie/now_playing?language=fr-FR&page=1&region=FR in C:\wamp64\www\sites\mon-site\library\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 211
Call Stack
# Time Memory Function Location
1 0.0006 364568 {main}( ) ...\API-now_playing.php:0
2 0.0041 375984 GuzzleHttp\Client->request( $method = 'GET', $uri = 'https://api.themoviedb.org/3/movie/now_playing?language=fr-FR&page=1&region=FR', $options = ['headers' => ['Authorization' => 'Bearer ey[...]HU', 'accept' => 'application/json']] ) ...\API-now_playing.php:7
3 0.1871 414024 GuzzleHttp\Promise\RejectedPromise->wait( $unwrap = ??? ) ...\Client.php:189

I therefore understood that the error comes from the fact that locally I do not have an SSL certificate. What can I do to fix this error? Is it possible to install a certificate locally? If yes, how to proceed?

Thank you for your time and your response.

I have this code below which works on server but not locally.

<?php
 
require_once('../../library/vendor/autoload.php');
 
$client = new \GuzzleHttp\Client();
 
$response = $client->request('GET', 'https://api.themoviedb.org/3/movie/now_playing?language=fr-FR&page=1&region=FR', [
    'headers' => [
        'Authorization' => 'Bearer ey[...]HU',
        'accept' => 'application/json',
    ],
]);
 
$rep = $response->getBody();
echo $rep;
 
?>

Upvotes: 1

Views: 347

Answers (1)

hrabia_f
hrabia_f

Reputation: 14

If you work locally you can just disable ssl verification inside your request. I hope one of these should work.

$response = $client->request('GET', 'https://example.com', [
RequestOptions::VERIFY => false,
]);

Or

$client = new Client(['verify' => false]);

Upvotes: 0

Related Questions