Cloud Datastore tutorial fails with exception

475 views
Skip to first unread message

Jay-Nicolas Hackleman

unread,
Jun 4, 2017, 4:59:43 PM6/4/17
to Google App Engine
Hi,


I'm attempting to run the code in the local dev_appserver, but I get the following exception:


Fatal error: Uncaught exception 'Google\Cloud\Core\Exception\ServiceException' with message 'curl_setopt_array(): cannot represent a stream of type MEMORY as a STDIO FILE*' in K:\AppEngineProjects\IronOakAppspot\vendor\google\cloud-core\RequestWrapper.php:241 Stack trace: #0 K:\AppEngineProjects\IronOakAppspot\vendor\google\cloud-core\RequestWrapper.php(150): Google\Cloud\Core\RequestWrapper->convertToGoogleException(Object(Google\Cloud\Core\Exception\ServiceException)) #1 K:\AppEngineProjects\IronOakAppspot\vendor\google\cloud-core\RestTrait.php(86): Google\Cloud\Core\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array) #2 K:\AppEngineProjects\IronOakAppspot\vendor\google\cloud-datastore\Connection\Rest.php(81): Google\Cloud\Datastore\Connection\Rest->send('projects', 'commit', Array) #3 K:\AppEngineProjects\IronOakAppspot\vendor\google\cloud-datastore\Operation.php(447): Google\Cloud\Datastore\Connection\Rest->commit(Array) #4 K:\AppEngineProjects\IronOakAppspot\vendor\google\cloud-datastore\DatastoreClient.php( in K:\AppEngineProjects\IronOakAppspot\vendor\google\cloud-core\RequestWrapper.php on line 241

How do I fix this?
Thanks

Yannick (Cloud Platform Support)

unread,
Jun 5, 2017, 4:39:21 PM6/5/17
to Google App Engine
Hello Jay-Nicolas. I have not been able to reproduce your issue when testing this code sample, so there might be something wrong with your environment. You can also go here to report an issue for this code sample. You could also try following the instructions from this tutorial.

Jay-Nicolas Hackleman

unread,
Jun 7, 2017, 3:20:12 PM6/7/17
to Google App Engine
Hi Yannick,
I'm posting my resolution here for people with the same issue.
Basically what it comes down to is that this issue occurs on windows running dev_appserver and attempting to test your application locally. I would be curious to know if you could reproduce it knowing that, as it seems I'm not alone.

I found someone reporting the issue to Guzzle here: https://github.com/guzzle/guzzle/issues/1640
and reported (in conjunction with another issue) to the google issue tracker here: https://issuetracker.google.com/issues/35900358

The resolution was to modify Guzzle code (which I'm really not happy about having to do) to support googles implementation of php in the dev environment.

I changed the file: 
\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php
line
370

At this statement:

$conf[CURLOPT_FILE] = fopen('php://temp', 'w+');

And added BELOW it:

//JAY_NIC_CHANGE: GUZZLE_GOOGLE_WINDOWS_CURL_IMPLEMENTATION
if(isset($_SERVER['SERVER_SOFTWARE']) 
&& 0 === strpos($_SERVER['SERVER_SOFTWARE'], 'Development/')) {
//echo "HEY HEREI AM";
$conf[CURLOPT_FILE] = fopen(getenv('temp').uniqid(), 'w+');
}



Of course, modifying a dependency's code is a no-no... But I'm not really sure what else I'm supposed to do...


In addition to this issue, I first had to overcome the same set of errors that this guy encountered (linked previously): https://issuetracker.google.com/issues/35900358
It seems that the certificate error: 
"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"
- was ALSO plaguing this implementation. Again, I'd love to know if you follow those steps on a windows machine and attempt to test in the dev environment: if you'd get the same results. I suspect so.

On a personal note: this is not the first time, (and I suspect not the last time) that the tutorials I've followed in the app engine just haven't worked, or have otherwise been vague, or incomplete. Being that I have deliverables to work with: I need to get this project done. But once it's working, I'm going to be moving the project over to heroku - I've followed all their tutorials, and things just work, no problems.


I hope this helps other people

Yannick (Cloud Platform Support)

unread,
Jun 9, 2017, 4:32:42 PM6/9/17
to Google App Engine
Hello Jay-Nicolas, thank you very much for the detailed answer. I did manage to replicate your issue when using the local dev server on a Windows 10 VM. The code does otherwise work on App Engine and when ran directly using a regular php installation.

I did also have to deal with the "No CA Bundle" error and I agree that our documentation isn't perfect but we are always striving to improve it.

Since I've already reproduced the issue I've gone ahead and created an issue for you on the Issue Tracker. It has been forwarded to the product team and I future updates for this issue will be posted there.

Jay-Nicolas Hackleman

unread,
Jun 10, 2017, 1:41:44 PM6/10/17
to Google App Engine
Awesome. That's great to hear, Yannick.
Reply all
Reply to author
Forward
0 new messages