【问题标题】:AuthorizationError: Expect status [201] from Google Storage. But got status 401AuthorizationError:期望来自 Google Storage 的状态 [201]。但得到状态 401
【发布时间】:2017-08-10 02:08:42
【问题描述】:

我正在尝试通过“App Engine”在谷歌云存储中创建一个新文件。我已授予存储桶服务帐户的完全权限,但仍然收到以下错误。

代码:

import cloudstorage as _gcs

from google.appengine.api import app_identity,urlfetch

class get_ad_insights(webapp.RequestHandler):
    def get(self):
        bucket_name = 'awstogcs'
        bucket = '/' + bucket_name
        filename = bucket + '/facebook_data'
        self.tmp_filenames_to_clean_up = []

        write_retry_params = _gcs.RetryParams(backoff_factor=1.1)
        gcs_file=_gcs.open(
            filename, 'w', content_type='text/plain', options={
                'x-goog-meta-foo': 'foo', 'x-goog-meta-bar': 'bar'},
                 retry_params=write_retry_params) 
        gcs_file.write('abcd\n')
        gcs_file.write('f'*1024*4 + '\n')
        gcs_file.close()
        self.tmp_filenames_to_clean_up.append(filename)

错误信息:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 267, in Handle
    result = handler(dict(self._environ), self._StartResponse)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "C:\Chaitu\Projects\fb\controllers\getinsights.py", line 40, in get
    retry_params=write_retry_params)
  File "lib\cloudstorage\cloudstorage_api.py", line 95, in open
    return storage_api.StreamingBuffer(api, filename, content_type, options)
  File "lib\cloudstorage\storage_api.py", line 699, in __init__
    body=content)
  File "lib\cloudstorage\errors.py", line 128, in check_status
    raise AuthorizationError(msg)
**AuthorizationError: Expect status [201] from Google Storage. But got status 401.**
Path: '/media-appengine/facebook_data'.
Request headers: {'content-type': 'text/plain', 'x-goog-meta-foo': 'foo', 'x-goog-api-version': '2', 'x-goog-resumable': 'start', 'x-goog-meta-bar': 'bar', 'accept-encoding': 'gzip, *'}.
Response headers: {'alt-svc': 'quic=":443"; ma=2592000; v="38,37,36,35"', 'content-type': 'application/xml; charset=UTF-8', 'date': 'Mon, 12 Jun 2017 19:17:37 GMT', 'www-authenticate': 'Bearer realm="https://accounts.google.com/", error="invalid_token"', 'content-length': '131', 'x-guploader-uploadid': 'AEnB2Uo4r-8lsPGFCJNsbukPIHyX1eHTS9pC9cMOmDFqwPr_8ERTdBpwa8ce1T5ri5Y5OaJ3Qx8ZRYVM8QwT1ImL5fjmsZguUg', 'vary': 'Origin', 'server': 'UploadServer'}.
Body: "<?xml version='1.0' encoding='UTF-8'?><Error><Code>AuthenticationRequired</Code><Message>Authentication required.</Message></Error>".
Extra info: None.

【问题讨论】:

  • 你是在本地运行吗?我想知道 google-cloud-sdk 是否可能对本地运行的开发服务器有一些身份验证错误。部署的时候有用吗?
  • 当我删除以下代码 options={ 'x-goog-meta-foo': 'foo', 'x-goog-meta-bar': 'bar'} 脚本正在运行。
  • 很奇怪。尽管我无法重现它,但这绝对看起来可能是一个错误。 google-cloud Python 客户端可能会让您更幸运:googlecloudplatform.github.io/google-cloud-python

标签: google-cloud-platform google-cloud-storage


【解决方案1】:

当我删除以下代码 options={ 'x-goog-meta-foo': 'foo', 'x-goog-meta-bar': 'bar'} 脚本正在运行

【讨论】:

    猜你喜欢
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 2016-04-04
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多