googleads / googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP
Apache License 2.0
655 stars 770 forks source link

cURL error 77: error setting certificate verify locations #313

Closed yooouuri closed 7 years ago

yooouuri commented 7 years ago

I am importing campaigns, adgroups, ads and keywords from a live account.

First I select a campaign and afterwards with that campaign id I select an adgroup etc etc

At some point, I get the following error...

[GuzzleHttp\Exception\RequestException]                                           
  cURL error 77: error setting certificate verify locations:                        
  CAfile: /etc/ssl/certs/ca-certificates.crt                                      
  CApath: /etc/ssl/certs (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

https://curl.haxx.se/libcurl/c/libcurl-errors.html says:

CURLE_SSL_CACERT_BADFILE (77) Problem with reading the SSL CA cert (path? access rights?)

The stack trace:

[2017-06-26 10:16:13] local.ERROR: GuzzleHttp\Exception\RequestException: cURL error 77: error setting certificate verify locations:
  CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:187
Stack trace:
#0 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#3 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(28): GuzzleHttp\Handler\CurlHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#4 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(51): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#5 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(72): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#6 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Middleware.php(30): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#7 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(68): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#8 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Middleware.php(59): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#9 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/HandlerStack.php(67): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#10 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Client.php(275): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#11 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Client.php(96): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array)
#12 /home/vagrant/Code/adwords/vendor/guzzlehttp/guzzle/src/Client.php(104): GuzzleHttp\Client->sendAsync(Object(GuzzleHttp\Psr7\Request), Array)
#13 /home/vagrant/Code/adwords/vendor/google/auth/src/HttpHandler/Guzzle6HttpHandler.php(34): GuzzleHttp\Client->send(Object(GuzzleHttp\Psr7\Request), Array)
#14 /home/vagrant/Code/adwords/vendor/google/auth/src/OAuth2.php(492): Google\Auth\HttpHandler\Guzzle6HttpHandler->__invoke(Object(GuzzleHttp\Psr7\Request))
#15 /home/vagrant/Code/adwords/vendor/google/auth/src/Credentials/UserRefreshCredentials.php(92): Google\Auth\OAuth2->fetchAuthToken(Object(Google\Auth\HttpHandler\Guzzle6HttpHandler))
#16 /home/vagrant/Code/adwords/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/OAuth2TokenRefresher.php(60): Google\Auth\Credentials\UserRefreshCredentials->fetchAuthToken()
#17 /home/vagrant/Code/adwords/vendor/googleads/googleads-php-lib/src/Google/AdsApi/AdWords/AdWordsHeaderHandler.php(72): Google\AdsApi\Common\Util\OAuth2TokenRefresher->getOrFetchAccessToken(Object(Google\Auth\Credentials\UserRefreshCredentials))
#18 /home/vagrant/Code/adwords/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php(86): Google\AdsApi\AdWords\AdWordsHeaderHandler->generateHttpHeaders(Object(Google\AdsApi\AdWords\AdWordsSession))
#19 /home/vagrant/Code/adwords/vendor/googleads/googleads-php-lib/src/Google/AdsApi/AdWords/v201609/cm/AdGroupAdService.php(215): Google\AdsApi\Common\AdsSoapClient->__soapCall('query', Array)
#20 /home/vagrant/Code/adwords/app/Edubookers/Manage/Import.php(418): Google\AdsApi\AdWords\v201609\cm\AdGroupAdService->query('SELECT Id, AdGr...')
#21 /home/vagrant/Code/adwords/app/Edubookers/Manage/Import.php(241): App\Edubookers\Manage\Import->adGroupAd(39549969053, Object(Closure))
#22 /home/vagrant/Code/adwords/app/Edubookers/Manage/Import.php(391): App\Edubookers\Manage\Import->App\Edubookers\Manage\{closure}(Object(Google\AdsApi\AdWords\v201609\cm\AdGroup))
#23 /home/vagrant/Code/adwords/app/Edubookers/Manage/Import.php(296): App\Edubookers\Manage\Import->adGroup(648323717, Object(Closure))
#24 /home/vagrant/Code/adwords/app/Edubookers/Manage/Import.php(326): App\Edubookers\Manage\Import->App\Edubookers\Manage\{closure}(Object(Google\AdsApi\AdWords\v201609\cm\Campaign))
#25 /home/vagrant/Code/adwords/app/Edubookers/Manage/Import.php(297): App\Edubookers\Manage\Import->campaign(Object(Closure))
#26 /home/vagrant/Code/adwords/app/Edubookers/Manage/Manage.php(26): App\Edubookers\Manage\Import->__construct('1', 'Regionaal Child...', NULL)
#27 /home/vagrant/Code/adwords/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): App\Edubookers\Manage\Manage->import('1', 'Regionaal Child...', NULL)
#28 /home/vagrant/Code/adwords/app/Console/Commands/Import.php(45): Illuminate\Support\Facades\Facade::__callStatic('import', Array)
#29 [internal function]: App\Console\Commands\Import->handle()
#30 /home/vagrant/Code/adwords/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#31 /home/vagrant/Code/adwords/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#32 /home/vagrant/Code/adwords/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#33 /home/vagrant/Code/adwords/vendor/laravel/framework/src/Illuminate/Container/Container.php(531): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#34 /home/vagrant/Code/adwords/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Illuminate\Container\Container->call(Array)
#35 /home/vagrant/Code/adwords/vendor/symfony/console/Command/Command.php(264): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#36 /home/vagrant/Code/adwords/vendor/laravel/framework/src/Illuminate/Console/Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#37 /home/vagrant/Code/adwords/vendor/symfony/console/Application.php(835): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /home/vagrant/Code/adwords/vendor/symfony/console/Application.php(200): Symfony\Component\Console\Application->doRunCommand(Object(App\Console\Commands\Import), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /home/vagrant/Code/adwords/vendor/symfony/console/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 /home/vagrant/Code/adwords/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#41 /home/vagrant/Code/adwords/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#42 {main} 
fiboknacky commented 7 years ago

Hi @yooouuri

As suggested by the message, could you please if your cert file is there (in /etc/ssl/certs/ca-certificates.crt) and the permission settings is correct?

Best, Knack

yooouuri commented 7 years ago

Hi @fiboknacky

ca-certificates.crt does exist:

vagrant@homestead:/etc/ssl/certs$ ls -all ca-certificates.crt
-rw-r--r-- 1 root root 274340 Mar 20 20:50 ca-certificates.crt

And when I run cat ca-certificates.crt as a non root user it shows me a bunch of certificates.

Best, Youri

fiboknacky commented 7 years ago

Hi Youri,

Does this happen to only when you use this library or other cases that use SSL as well, e.g., git clone? And could you try testing your CA as described here?

Best, Knack

yooouuri commented 7 years ago

This only happen when i'm using this library. I am going to test the CA, ill keep in touch.

Edit: @fiboknacky on what url do i need to test the certificates?

Edit 2: @fiboknacky The result is given below:

Verify return code: 0 (ok)

Thanks for the help.

Best, Youri

fiboknacky commented 7 years ago

Could you try injecting your CA file using SoapSettingsBuilder::withSslCaFile()? Try putting the CA file in a different path than that of your default CA file.

After setting that, you can create a custom SOAP settings object using build().

Then, you can create an AdWordsSession using the created SOAP settings object in the previous step by using withSoapSettings()

And if still doesn't work, could you please try this CA from Mozilla (mentioned in the Guzzle reference doc)?

yooouuri commented 7 years ago

Hi @fiboknacky

Tried the both solutions, no luck. Used ca-certificates.crt from the system and downloaded ca-bundle.crt

->withSoapSettings((new SoapSettingsBuilder())
                ->withSslCaFile('/home/***/ca-bundle.crt') 
                ->build())
fiboknacky commented 7 years ago

Hello @yooouuri

Could you please try using Guzzle purely? I searched in the internet and found some cases that Guzzle has a problem with Vagrant. If it's the same for your case, we may need to ask in Guzzle issues tracker too.

Best, Knack

fiboknacky commented 7 years ago

Close due to inactivity. Please feel free to get back to us if you still have this problem.

ZahoorAhmad commented 4 years ago

Facing this issue still