我在一个项目中设置了一个存储桶来存储上传的文件。尝试确保我可以使用将文件上传到失败的测试节点程序来写入存储桶。然后,我尝试使用gsutil将文件复制到存储桶中,然后重试直到超时。经过进一步调查,使用gsutil的每个命令都会导致超时错误。互联网上关于此错误的信息似乎很少。

我已使用gcloud init删除并重新生成了.boto文件。此命令有效。我还对SDK进行了两次干净的重新安装,仍然有问题。该项目的ACL和存储桶包含了我。下面是gsutil cp test.txt gs://mybucket的节点程序和超时错误

const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
const bucketName = 'mybucket';
const filename = 'test.txt';

// Uploads a local file to the bucket
storage.bucket(bucketName).upload(filename, {
  // Support for HTTP requests made with `Accept-Encoding: gzip`
  gzip: true,
  metadata: {
    // Enable long-lived HTTP caching headers
    // Use only if the contents of the file will never change
    // (If the contents will change, use cacheControl: 'no-cache')
    cacheControl: 'public, max-age=31536000',
  },
});

console.log(`${filename} uploaded to ${bucketName}.`);

节点程序错误
(node:18471) UnhandledPromiseRejectionWarning: Error: Anonymous caller does not have storage.objects.create access to medchainvault/test.txt.
    at Util.parseHttpRespBody (/home/russell/go/src/github.com/medchain/business-network/storage-server/node_modules/@google-cloud/common/build/src/util.js:172:38)
    at Util.handleResp (/home/russell/go/src/github.com/medchain/business-network/storage-server/node_modules/@google-cloud/common/build/src/util.js:116:117)
    at retryRequest (/home/russell/go/src/github.com/medchain/business-network/storage-server/node_modules/@google-cloud/common/build/src/util.js:403:22)
    at onResponse (/home/russell/go/src/github.com/medchain/business-network/storage-server/node_modules/@google-cloud/common/node_modules/retry-request/index.js:200:7)
    at /home/russell/go/src/github.com/medchain/business-network/storage-server/node_modules/teeny-request/build/src/index.js:158:17
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
(node:18471) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:18471) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


来自gsutil的错误:

Traceback (most recent call last):    0.0 B/s
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gsutil", line 22, in <module>
    gsutil.RunMain()
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gsutil.py", line 117, in RunMain
    sys.exit(gslib.__main__.main())
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 407, in main
    perf_trace_token=perf_trace_token, user_project=user_project)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 590, in _RunNamedCommandAndHandleExceptions
    user_project=user_project)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/command_runner.py", line 372, in RunNamedCommand
    return_code = command_inst.RunCommand()
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/commands/cp.py", line 1184, in RunCommand
    seek_ahead_iterator=seek_ahead_iterator)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/command.py", line 1420, in Apply
    arg_checker, should_return_results, fail_on_error)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/command.py", line 1491, in _SequentialApply
    worker_thread.PerformTask(task, self)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/command.py", line 2157, in PerformTask
    results = task.func(cls, task.args, thread_state=self.thread_gsutil_api)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/commands/cp.py", line 795, in _CopyFuncWrapper
    preserve_posix=cls.preserve_posix_attrs)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/commands/cp.py", line 992, in CopyFunc
    gzip_exts=self.gzip_exts, preserve_posix=preserve_posix))
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/utils/copy_helper.py", line 3520, in PerformCopy
    allow_splitting=allow_splitting, gzip_encoded=gzip_encoded)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/utils/copy_helper.py", line 2026, in _UploadFileToObject
    parallel_composite_upload, logger)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/utils/copy_helper.py", line 1877, in _DelegateUploadFileToObject
    elapsed_time, uploaded_object = upload_delegate()
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/utils/copy_helper.py", line 2009, in CallNonResumableUpload
    gzip_encoded=gzip_encoded_file)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/utils/copy_helper.py", line 1588, in _UploadFileToObjectNonResumable
    fields=UPLOAD_RETURN_FIELDS, gzip_encoded=gzip_encoded)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/cloud_api_delegator.py", line 292, in UploadObject
    gzip_encoded=gzip_encoded)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/gcs_json_api.py", line 1385, in UploadObject
    gzip_encoded=gzip_encoded)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/gcs_json_api.py", line 1229, in _UploadObject
    global_params=global_params)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/third_party/storage_apitools/storage_v1_client.py", line 1197, in Insert
    download=download)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/apitools/apitools/base/py/base_api.py", line 729, in _RunMethod
    http, http_request, **opts)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/apitools/apitools/base/py/http_wrapper.py", line 346, in MakeRequest
    check_response_func=check_response_func)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/apitools/apitools/base/py/http_wrapper.py", line 396, in _MakeRequestNoRetry
    redirections=redirections, connection_type=connection_type)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/gcs_json_media.py", line 276, in NewRequest
    connection_type=override_connection_type)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/oauth2client/oauth2client/transport.py", line 159, in new_request
    credentials._refresh(orig_request_method)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/oauth2client/oauth2client/client.py", line 761, in _refresh
    self._do_refresh_request(http)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/google-reauth-python/google_reauth/reauth_creds.py", line 120, in _do_refresh_request
    headers=headers))
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/google-reauth-python/google_reauth/reauth.py", line 269, in refresh_access_token
    headers=headers)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/google-reauth-python/google_reauth/_reauth_client.py", line 151, in refresh_grant
    headers=headers)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/google-reauth-python/google_reauth/reauth_creds.py", line 107, in http_request
    body=body, headers=headers)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/oauth2client/oauth2client/transport.py", line 282, in request
    connection_type=connection_type)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/httplib2/python2/httplib2/__init__.py", line 1694, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/httplib2/python2/httplib2/__init__.py", line 1434, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/gcs_json_media.py", line 529, in _conn_request
    conn.connect()
  File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/httplib2/python2/httplib2/__init__.py", line 1100, in connect
    sock.connect(sockaddr)
  File "/usr/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.timeout: timed out


最佳答案

我假设这是一个作为服务器运行的node.js项目,而不是 bundle 在浏览器中运行的代码。

您的问题在此行中定义:

Error: Anonymous caller does not have storage.objects.create access to medchainvault/test.txt.

此错误表示您的代码未使用凭据。

通常,这行代码将使用ADC选择您的凭据之一:
const storage = new Storage();

但是,没有找到。

您有几种选择:
  • 运行gcloud auth login以设置凭据。
  • 创建服务帐户,下载Json文件,并在创建客户端时使用这些凭证(推荐)。

  • 使用类似于以下代码:
    const storage = new Storage({
      projectId: 'project-id',
      keyFilename: '/path/to/keyfile.json'
    });
    

    关于javascript - gsutil在每个命令上均超时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54373324/

    10-10 23:29