目前,我能够在部署代码后写入数据存储,但是我不能在本地运行代码的数据存储仿真器,因为它会引发ca-bundle错误。本地数据存储可以在localhost上看到:8000。
use google\appengine\api\users\User;
use google\appengine\api\users\UserService;
use google\appengine\api\app_identity\AppIdentityService;
echo AppIdentityService::getApplicationId()."<br>";
echo AppIdentityService::getDefaultVersionHostname()."<br>";
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\ServiceBuilder;
$cloud = new ServiceBuilder([
'projectId' => AppIdentityService::getApplicationId(),
'keyFilePath'=>'review-9504000716d8.json'
]);
$datastore = $cloud->datastore();
# The kind for the new entity
$kind = 'Task';
# The name/ID for the new entity
$name = 'sampletask1';
# The Cloud Datastore key for the new entity
$taskKey = $datastore->key($kind, $name);
# Prepares the new entity
$task = $datastore->entity($taskKey, ['description' => 'Buy milk']);
# Saves the entity
$datastore->upsert($task);此代码在部署时运行时没有任何问题。但本地抛出:
Fatal error: Uncaught exception 'Google\Cloud\Exception\ServiceException' with message 'No system CA bundle could be found in any of the the common system locations. PHP versions earlier than 5.6 are not properly configured to use the system's CA bundle by default. In order to verify peer certificates, you will need to supply the path on disk to a certificate bundle to the 'verify' request option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not need a specific certificate bundle, then Mozilla provides a commonly used CA bundle which can be downloaded here (provided by the maintainer of cURL): https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP ini setting to point to the path to the file, allowing you to omit the 'verify' request option. See http://curl.haxx.se/docs/sslcerts.html for more information.' in D:\Google\php\appengine-php-guestbook-phase0-helloworld\appengine-php-guestbook-phase0-hellowo in D:\Google\php\appengine-php-guestbook-phase0-helloworld\appengine-php-guestbook-phase0-helloworld\vendor\google\cloud\src\RequestWrapper.php on line 219我甚至没有让本地服务器考虑php.ini文件,也没有将捆绑的php55升级到至少php56。
因此,我实际上有两个问题:
发布于 2017-01-12 17:33:17
API正在使用CA证书文件进行身份验证,更具体地说,它们使用的是curl.cainfo。
现在,您的服务器可能已经在php.ini中配置了该文件。您可以签入服务器文件。记住,对于apache、cli这样的不同环境,可能会有不同的ini文件。
现在,您可以复制该文件或创建您自己的权限文件。
备选案文1:
在php.ini中设置绝对路径
备选案文2:
使用ini_set设置此配置。
备选方案3:
尝试一些其他的认证模式,我相信谷歌会有这方面的。
备选案文4:
就像你在问题中说的那样。
如果您不需要特定的证书包,那么Mozilla提供了一个常用的CA包,可以在这里下载https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt。一旦磁盘上有了CA包,就可以将“openssl.cafile”PHP设置设置为指向文件的路径,从而可以省略“验证”请求选项。
https://stackoverflow.com/questions/41382108
复制相似问题