Error using Requests library w/ eval-file
mAAdhaTTah opened this issue · 5 comments
I was using eval-file
to write some quick-and-dirty tests of a client wrapper around some API calls using Requests. However, I struggled for a while because every time I ran it, I got this Exception raised:
[02-Aug-2017 02:26:28 UTC] PHP Fatal error: Uncaught Requests_Exception: cURL error 77: error setting certificate verify locations:
CAfile: phar:///usr/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cacert.pem
CApath: /etc/ssl/certs in phar:///usr/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php:422
Stack trace:
#0 phar:///usr/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php(177): Requests_Transport_cURL->process_response('', Array)
#1 phar:///usr/bin/wp/vendor/rmccue/requests/library/Requests.php(379): Requests_Transport_cURL->request('https://api.git...', Array, Array, Array)
#2 phar:///usr/bin/wp/vendor/rmccue/requests/library/Requests.php(706): Requests::request('https://api.git...', Array, Array, 'GET', Array)
#3 phar:///usr/bin/wp/vendor/rmccue/requests/library/Requests.php(383): Requests::parse_response(Array, 'http://api.gith...', Array, Array, Array)
#4 phar:///usr/bin/wp/vendor/rmccue/requests/library/Requests/Session.php(205): Requests::request('http://api.gith...', Array, Array, 'GET', Array)
in phar:///usr/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php on line 422
It cannot find a certificate required for making the SSL'd HTTP requests, but I didn't have this problem making requests from within WordPress (I stuck the same code on a dummy page and loaded it up and it ran fine). After some digging, I found in WordPress itself this line:
Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
which sets the location of WP's certificate path. I'm not sure why this wasn't set correctly when running from WP-CLI, but adding that to the top of my script resolved the issue.
I haven't dug deeper into what's going on yet, but Requests is bundled w/ WP-CLI and appears to be loading that version before the WP version, so I suspect it's related to that. I also don't know if this is just a problem with eval-file
or if other commands could have this problem.
I am running the latest version:
WP-CLI 1.2.1
I was using
eval-file
to write some quick-and-dirty tests of a client wrapper around some API calls using Requests.
Can you share this test case so we can reproduce?
I'll work on putting together a stand-alone test case this evening, but for now, here are the relevant files in the app I'm working on:
This is the script I'm eval-file
'ing.
This is the client file I'm actually trying to test (referenced by $client
in the script above).
@mAAdhaTTah Were you able to track down the source of this issue?
I know at least I fixed it with this. Doesn't appear I ever pulled this into a stand-alone, reproducible test-case.
I get this error as well on any command loading wp when I use the Requests
library. @mAAdhaTTah's workaround works though.
Do you want me to open a new ticket in wp-cli/wp-cli
?