I just started using python so my apologies if the question sounds stupid.My web application is in php and i am calling gsutil from php using shell_exec.I am getting the following error
which: no python2 in ((null)) which: no python2.7 in ((null)) Traceback (most recent call last): File "/usr/local/bin/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 75, in main() File "/usr/local/bin/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 59, in main 'platform/gsutil', 'gsutil', *args) File "/usr/local/bin/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 45, in ExecutePythonTool execution_utils.ArgsForPythonTool(_FullPath(tool_dir, exec_name), *args)) File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/execution_utils.py", line 170, in ArgsForPythonTool python_executable = kwargs.get('python') or GetPythonExecutable() File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/execution_utils.py", line 59, in GetPythonExecutable raise ValueError('Could not find Python executable.') ValueError: Could not find Python executable.
My upload command is as follows
$upload_command = 'python="/usr/bin/python" /usr/local/bin/google-cloud-sdk/bin/gsutil -h "Cache-Control:max-age=31536000, public" cp ' . $tmp_path . ' gs://imgtest/'.$filename;
gcloud info
`Google Cloud SDK [138.0.0]
Platform: [Linux, x86_64]
Python Version: [2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]]
Python Location: [/usr/bin/python2]
Site Packages: [Disabled]
Installation Root: [/usr/local/bin/google-cloud-sdk]
Installed Components:
core: [2016.12.09]
core-nix: [2016.11.07]
gcloud: []
gsutil-nix: [4.18]
gsutil: [4.22]
bq: [2.0.24]
bq-nix: [2.0.24]
System PATH: [/usr/local/bin/google-cloud-sdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin]
Cloud SDK on PATH: [True]
Kubectl on PATH: [False]
Installation Properties: [/usr/local/bin/google-cloud-sdk/properties]
User Config Directory: [/root/.config/gcloud]
Active Configuration Name: [default]
Active Configuration Path: [/root/.config/gcloud/configurations/config_default] `
OS : Centos 7
Since this issue is occurring in gcloud wrapper code prior to gsutil being executed, I'd suggest migrating the issue to the gcloud issue tracker. StackOverflow may be an alternative if you can't get traction there.
That said, I'd check out the Python module search path documentation first. Are you able to execute other Python scripts from php?
@khavishbhundoo Try this workaround.
$upload_command="CLOUDSDK_PYTHON=/usr/bin/python YOUR_UPLOAD_COMMAND"
Other references: #236
@hidekuro
Thanks for the help on this issue
Now i get the following error
Traceback (most recent call last): File "/usr/local/bin/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 75, in main() File "/usr/local/bin/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 22, in main project, account = bootstrapping.GetActiveProjectAndAccount() File "/usr/local/bin/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 205, in GetActiveProjectAndAccount project_name = properties.VALUES.core.project.Get(validate=False) File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/properties.py", line 1176, in Get required) File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/properties.py", line 1456, in _GetProperty value = _GetPropertyWithoutDefault(prop, properties_file) File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/properties.py", line 1494, in _GetPropertyWithoutDefault value = callback() File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/properties.py", line 670, in _GetGCEProject return c_gce.Metadata().Project() File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/credentials/gce.py", line 203, in Metadata _metadata_lock.lock(function=_CreateMetadata, argument=None) File "/usr/lib64/python2.7/mutex.py", line 44, in lock function(argument) File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/credentials/gce.py", line 202, in _CreateMetadata _metadata = _GCEMetadata() File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/credentials/gce.py", line 59, in __init__ self.connected = gce_cache.GetOnGCE() File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/credentials/gce_cache.py", line 141, in GetOnGCE return _SINGLETON_ON_GCE_CACHE.GetOnGCE(check_age) File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/credentials/gce_cache.py", line 80, in GetOnGCE self._WriteDisk(on_gce) File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/credentials/gce_cache.py", line 112, in _WriteDisk with files.OpenForWritingPrivate(gce_cache_path) as gcecache_file: File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/util/files.py", line 708, in OpenForWritingPrivate MakeDir(full_parent_dir_path, mode=0700) File "/usr/local/bin/google-cloud-sdk/lib/googlecloudsdk/core/util/files.py", line 113, in MakeDir (u'Please verify that you have permissions to write to the parent ' googlecloudsdk.core.util.files.Error: Could not create directory [/home/nginx/.config/gcloud]: Permission denied. Please verify that you have permissions to write to the parent directory.
gcloud info
Google Cloud SDK [142.0.0]
Platform: [Linux, x86_64]
Python Version: [2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]]
Python Location: [/usr/bin/python2]
Site Packages: [Disabled]Installation Root: [/usr/local/bin/google-cloud-sdk]
Installed Components:
core: [2017.01.27]
core-nix: [2016.11.07]
gcloud: []
gsutil-nix: [4.18]
gsutil: [4.22]
bq: [2.0.24]
bq-nix: [2.0.24]
System PATH: [/usr/local/bin/google-cloud-sdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin]
Cloud SDK on PATH: [True]
Kubectl on PATH: [False]Installation Properties: [/usr/local/bin/google-cloud-sdk/properties]
User Config Directory: [/root/.config/gcloud]
Active Configuration Name: [default]
Active Configuration Path: [/root/.config/gcloud/configurations/config_default]Account: [[email protected]]
Project: [image-hidden_data]Current Properties:
[core]
project: [test-143606]
account: [[email protected]]
disable_usage_reporting: [True]Logs Directory: [/root/.config/gcloud/logs]
Last Log File: [/root/.config/gcloud/logs/2017.02.02/01.42.24.695027.log]
Although i installed google cloud sdk in /usr/local , why is the User Config Directory in /root ?
Does the user config directory need to be in a directory that is writable by php-fpm ?
How do i change the directory if need be ?
1) It looks like you may have ran gcloud info
as the root
user, or ran it under the sudo
command.
2) From the very last bits of your stack trace:
Could not create directory [/home/nginx/.config/gcloud]: Permission denied. Please verify that you have permissions to write to the parent directory.
It appears that the user executing your shell_exec command (which looks like the nginx
user) doesn't have permissions to create that folder... I assume this is because the nginx
user traditionally doesn't have their own home directory. Since /home is owned by root
, nginx
won't have permission to create the /home/nginx folder.
I had this problem using Nginx_Rtmp_Module exec. It seems like it creates a new env while running the Gsutil api, even using "bash -c" to run it. So i had to do what @hidekuro said (i wish i had read his statement early, had to go after the error on gcloud core code =/).
About your permission denied, look for Nginx conf, on first line it should be the user that it uses.
See if he has the permission to create a folder there. (If you changed the Nginx's users, it's possible it wont write then)
As this seems to be an issue with your local system (varying users, permissions, and file paths), I'm going to close this.
I had same issue when executing gcloud commands.
which: no python2 in (/opt/google-cloud-sdk/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin)
I resolve this by adding symbolic link to "/usr/bin/python"
Most helpful comment
@khavishbhundoo Try this workaround.
Other references: #236