首页 > 解决方案 > Gsutil 错误“捕获套接字错误,重试:超时”

问题描述

几天以来,我一直面临着这个问题。
我已经在使用 Vagrant 构建的 Fedora 34 VM 上安装了 Gcloud sdk。
我已经执行了gcloud init,gcloud auth logingcloud config set project <my_project>.
在过去的几天里,我无法正确使用 gsutil。我在这篇文章中找到了一些参考:Gsutil Always Time Out,建议使用选项 -D 来调试 gsutil。

在使用 gsutil 之前,我设置了存储桶名称变量并执行命令授权服务帐户“<service_account>@<my_project>.iam.gserviceaccount.com”:

export GCS_BUCKET_URL="gs://<my_project>-<string>/<bucket_subname>/"
gcloud auth activate-service-account --key-file=/home/<myuser>/DEV/auth/credentials.json

当我执行“ gsutil -D cp ./gcp-config "${GCS_BUCKET_URL}/data-${date_time}/gcp-config”时,我确实看到:

gsutil version: 5.4
checksum: <checksum> (OK)
boto version: 2.49.0
python version: 3.9.7 (default, Aug 30 2021, 00:00:00) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]
OS: Linux 5.14.13-200.fc34.x86_64
multiprocessing available: True
using cloud sdk: True
pass cloud sdk credentials to gsutil: True
config path(s): /home/<myuser>/.boto, /home/<myuser>/.config/gcloud/legacy_credentials/<gserviceaccount.dir>/.boto
gsutil path: /home/<myuser>/google-cloud-sdk/bin/gsutil
compiled crcmod: False
installed via package manager: False
editable install: False
Command being run: /home/<myuser>/google-cloud-sdk/platform/gsutil/gsutil -o GSUtil:default_project_id=<my_project> -D cp ./gcp-config gs://<my_project>-<string>/<bucket_subname>/data-211027082549/gcp-config
config_file_list: ['/home/<myuser>/.boto', '/home/<myuser>/.config/gcloud/legacy_credentials/<service_account>@<my_project>.iam.gserviceaccount.com/.boto']
config: [('working_dir', '/mnt/pyami'), ('debug', '0'), ('https_validate_certificates', 'True'), ('working_dir', '/mnt/pyami'), ('debug', '0'), ('content_language', 'en'), ('default_api_version', '2'), ('default_project_id', '<my_project>')]
DEBUG 1027 08:35:42.782979 multiprocess_file_storage.py] Read credential file
DEBUG 1027 08:35:42.783419 multiprocess_file_storage.py] Read credential file
INFO 1027 08:35:42.784689 base_api.py] Calling method storage.objects.list with StorageObjectsListRequest: <StorageObjectsListRequest
 bucket: '<my_project>-<string>'
 delimiter: '/'
 maxResults: 1000
 prefix: '<bucket_subname>/data-211027082549/gcp-config'
 projection: ProjectionValueValuesEnum(noAcl, 1)>
INFO 1027 08:35:42.785718 base_api.py] Making http GET to https://storage.googleapis.com/storage/v1/b/<my_project>-<string>/o?alt=json&fields=nextPageToken%2Cprefixes%2Citems%2Fname&delimiter=%2F&maxResults=1000&prefix=<bucket_subname>%2Fdata-211027082549%2Fgcp-config&projection=noAcl
INFO 1027 08:35:42.786104 base_api.py] Headers: {'accept': 'application/json',
 'accept-encoding': 'gzip, deflate',
 'content-length': '0',
 'user-agent': 'apitools Python/3.9.7 gsutil/5.4 (linux) analytics/enabled '
               'interactive/True command/cp google-cloud-sdk/362.0.0'}
INFO 1027 08:35:42.786389 base_api.py] Body: (none)
INFO 1027 08:35:42.786540 transport.py] Attempting refresh to obtain initial access_token
DEBUG 1027 08:35:42.786998 multiprocess_file_storage.py] Read credential file
DEBUG 1027 08:35:42.787312 multiprocess_file_storage.py] Read credential file
DEBUG 1027 08:35:42.790359 crypt.py] [<crypt_data>]
INFO 1027 08:35:42.790598 client.py] Refreshing access_token
INFO 1027 08:36:42.926645 retry_util.py] Retrying request, attempt #1...
DEBUG 1027 08:36:42.927215 http_wrapper.py] Caught socket error, retrying: timed out
DEBUG 1027 08:36:42.927584 http_wrapper.py] Retrying request to url https://storage.googleapis.com/storage/v1/b/<my_project>-<string>/o?alt=json&fields=nextPageToken%2Cprefixes%2Citems%2Fname&delimiter=%2F&maxResults=1000&prefix=<bucket_subname>%2Fdata-211027082549%2Fgcp-config&projection=noAcl after exception timed out
INFO 1027 08:36:44.856812 transport.py] Attempting refresh to obtain initial access_token
DEBUG 1027 08:36:44.858911 multiprocess_file_storage.py] Read credential file
DEBUG 1027 08:36:44.859711 multiprocess_file_storage.py] Read credential file
DEBUG 1027 08:36:44.862151 crypt.py] [<crypt_data>]
INFO 1027 08:36:44.862644 client.py] Refreshing access_token
INFO 1027 08:37:44.899579 retry_util.py] Retrying request, attempt #2...
DEBUG 1027 08:37:44.903247 http_wrapper.py] Caught socket error, retrying: timed out
DEBUG 1027 08:37:44.905944 http_wrapper.py] Retrying request to url https://storage.googleapis.com/storage/v1/b/<my_project>-<string>/o?alt=json&fields=nextPageToken%2Cprefixes%2Citems%2Fname&delimiter=%2F&maxResults=1000&prefix=<bucket_subname>%2Fdata-211027082549%2Fgcp-config&projection=noAcl after exception timed out
INFO 1027 08:37:49.982855 transport.py] Attempting refresh to obtain initial access_token
DEBUG 1027 08:37:49.983732 multiprocess_file_storage.py] Read credential file
DEBUG 1027 08:37:49.984001 multiprocess_file_storage.py] Read credential file
DEBUG 1027 08:37:49.985360 crypt.py] [<crypt_data>]
INFO 1027 08:37:49.985699 client.py] Refreshing access_token
INFO 1027 08:38:50.090714 retry_util.py] Retrying request, attempt #3...

这会重复多次重试。
我检查了凭据文件(.boto 文件),它们看起来不错。
服务帐户“<service_account>@<my_project>.iam.gserviceaccount.com”对存储桶 gs://<my_project>- 具有“安全管理员”和“存储管理员”权限。
我曾尝试重新安装 Gcloud SDK,但对这种情况没有帮助。
这个答案看来,我的虚拟机上的 gsutil 面临代理问题。
因此,我还尝试了不安全选项来更改路由器上的安全级别:

  1. 禁用防火墙
  2. 启用 WAN ping (按照本主题
    我仍然有相同的行为。

GoogleDocs/GoogleSDK install我读到:“Cloud SDK 需要 Python;支持的版本是 Python 3(首选,3.5 到 3.8)和 Python 2(2.7.9 或更高版本)。”
由于我的 python 版本是3.9.7,我想知道这是否是问题所在。

任何建议都会在这里有所帮助。提前致谢!

更新
我已经更改了 python 版本,安装了 3.6.15,但它并没有解决问题。

标签: google-cloud-platformgcloudgsutil

解决方案


最后,这对我有用。对于 Vagrant 管理的 vm,eth0 是 Vagrant 用作执行远程命令的设备的 NAT 接口。第二个接口,在我的例子中是 eth1,是供个人使用的。我的 eth1 是桥接的。我试过这个:

  1. eth1->设置-> IPv4
  2. 将 IPv4 方法从“自动 (DHCP)”更改为“手动”
  3. 使用正确的网络掩码和网关设置静态 IP
  4. 重新加载 eth1 设置(关闭/打开 eth1)
  5. 如上所述尝试了 gsutil。

嗯,它工作得很好。

我真的希望这个答案可以帮助其他人,我只花了大约 8 个工作小时。

加油~!


推荐阅读