为谷歌存储桶创建签名 URL 的问题

Posted

技术标签:

【中文标题】为谷歌存储桶创建签名 URL 的问题【英文标题】:Issue creating Signed URL for google storage bucket 【发布时间】:2021-11-27 15:18:46 【问题描述】:

我正在尝试创建一个签名 URL 并将其运行到缺少库 pyopenssl 问题。我的命令如下:

gsutil signurl -d 10d -u /Users/dineshc/Development/my_key.json gs://console.cloud.google.com/storage/browser/my_data

我收到以下错误:

CommandException:signurl 命令需要 pyopenssl 库(尝试 pip install pyopenssl 或 easy_install pyopenssl)

我的操作系统配置如下:

uname      :    Darwin
ProductName:    macOS
ProductVersion: 11.4
BuildVersion:   20F71


I have python3.7 installed & I created symbolic link: 

ln -s /usr/local/bin/python3.7 /usr/local/bin/python

$ls -l /usr/local/bin/python*
lrwxr-xr-x  1 root  wheel  24  6 Oct 16:50 /usr/local/bin/python -> /usr/local/bin/python3.7
lrwxr-xr-x  1 root  wheel  69  6 Oct 16:04 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3
lrwxr-xr-x  1 root  wheel  76  6 Oct 16:04 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3-config
lrwxr-xr-x  1 root  wheel  71  6 Oct 16:04 /usr/local/bin/python3.7 -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
lrwxr-xr-x  1 root  wheel  78  6 Oct 16:04 /usr/local/bin/python3.7-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7-config
lrwxr-xr-x  1 root  wheel  72  6 Oct 16:04 /usr/local/bin/python3.7m -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m
lrwxr-xr-x  1 root  wheel  79  6 Oct 16:04 /usr/local/bin/python3.7m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m-config

$python --version
Python 3.7.9

$which pip3
/usr/local/bin/pip3

$which pip

<nothing is coming up here but the command below shows that pip is installed>

$pip3 install pip
Requirement already satisfied: pip in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (21.2.4)

$pip install pyopenssl
-bash: pip: command not found


$pip3 install pyopenssl
Requirement already satisfied: pyopenssl in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (21.0.0)
Requirement already satisfied: six>=1.5.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pyopenssl) (1.16.0)
Requirement already satisfied: cryptography>=3.3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pyopenssl) (35.0.0)
Requirement already satisfied: cffi>=1.12 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from cryptography>=3.3->pyopenssl) (1.14.6)
Requirement already satisfied: pycparser in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from cffi>=1.12->cryptography>=3.3->pyopenssl) (2.20)

$echo $PATH
/Users/dineshc/Development/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

$ls -l /usr/local/bin/python*
lrwxr-xr-x  1 root  wheel  24  6 Oct 16:50 /usr/local/bin/python -> /usr/local/bin/python3.7
lrwxr-xr-x  1 root  wheel  69  6 Oct 16:04 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3
lrwxr-xr-x  1 root  wheel  76  6 Oct 16:04 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3-config
lrwxr-xr-x  1 root  wheel  71  6 Oct 16:04 /usr/local/bin/python3.7 -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
lrwxr-xr-x  1 root  wheel  78  6 Oct 16:04 /usr/local/bin/python3.7-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7-config
lrwxr-xr-x  1 root  wheel  72  6 Oct 16:04 /usr/local/bin/python3.7m -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m
lrwxr-xr-x  1 root  wheel  79  6 Oct 16:04 /usr/local/bin/python3.7m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m-config

我的问题:出于某种原因(我认为)gsutil 仍然指的是 python2.5,这是 MacOS 附带的版本并且没有安装 pip。知道如何让 gsutil 使用最新版本的 python 和后续库吗?

【问题讨论】:

【参考方案1】:

您可以运行gsutil -D version 并获得许多有用的调试信息,包括您的 gsutil 安装、用于运行它的 Python 版本、正在加载的配置文件等。

如果您正在运行 gsutil 的 gcloud 安装,您应该会在输出中看到如下所示的一行:

gsutil path: <path-to-google-cloud-sdk>/bin/gsutil

在这种情况下,您应该能够使用 CLOUDSDK_GSUTIL_PYTHON 环境变量 as mentioned in these docs 指定首选 Python 解释器的路径。

但是,如果您正在运行独立安装 gsutil(不是 gcloud 安装的一部分),则应确保通过命令 /usr/bin/env python 启动的 Python 版本是正确的版本——这将是第一个 Python 二进制文件可从您的 PATH 环境变量中指定的目录中发现,因此您可能需要适当地编辑和 export 您的 PATH

【讨论】:

以上是关于为谷歌存储桶创建签名 URL 的问题的主要内容,如果未能解决你的问题,请参考以下文章

整个存储桶的预签名 url

如何使用签名的 URL 将文件上传到谷歌云存储桶

AWS CloudFront 签名 URL 的访问被拒绝

使用预签名 URL 上传到 S3 存储桶会出现 403 禁止错误

使用 AlamoFire 和预签名 URL 将图像上传到 S3 存储桶时出现问题

使用 Ruby 为 CloudFront 创建签名 URL