Google Python storage authorization issues + Google Cloud Storage

I am trying to run the Google Cloud Storage + Google App Engine (Python) Hello World application.

I followed the instructions to activate Google Cloud Storage and created a bucket from the App Engine application console. I wrote a trivial program to write a test file, but when I run it, the cloud storage library throws 403, apparently because my App Engine application credentials are not presented, are invalid or do not have the right to this bucket.

Here is the code:

BUCKET = '/pcj-info-testing'

class TestGCS(webapp2.RequestHandler):
  def create_file(self, filename):
    self.response.write("Creating\n");
    gcs_file = gcs.open(filename, 'w', content_type = 'text/plain');
    gcs_file.write('Testing, 1, 2, 3\n')
    gcs_file.write('At ' + datetime.now().isoformat())    
    gcs_file.close()

  def get(self):
    self.response.headers['Content-Type'] = 'text/plain'
    filename = BUCKET + "/demo-file" + str(random.randrange(10**10, 10**11-1))
    self.create_file(filename)
    self.response.write('File stat:\n')
    stat = gcs.stat(filename)
    self.response.write(repr(stat))

and here is the relevant part of the stack trace and error:

  File "/base/data/home/apps/s~pcj-info/1.373629132682543570/gcstest.py", line 14, in create_file
    gcs_file = gcs.open(filename, 'w', content_type = 'text/plain');
  File "/base/data/home/apps/s~pcj-info/1.373629132682543570/cloudstorage/cloudstorage_api.py", line 74, in open
    return storage_api.StreamingBuffer(api, filename, content_type, options)
  File "/base/data/home/apps/s~pcj-info/1.373629132682543570/cloudstorage/storage_api.py", line 597, in __init__
    errors.check_status(status, [201], path, headers, resp_headers)
  File "/base/data/home/apps/s~pcj-info/1.373629132682543570/cloudstorage/errors.py", line 106, in check_status
    raise ForbiddenError(msg)
ForbiddenError: Expect status [201] from Google Storage. But got status 403.
Path: '/pcj-info-testing/demo-file16955619179'.
Request headers: {'x-goog-resumable': 'start', 'x-goog-api-version': '2', 'content-type': 'text/plain', 'accept-encoding': 'gzip, *'}.
Response headers: {'alternate-protocol': '443:quic', 'content-length': '146', 'via': 'HTTP/1.1 GWA', 'x-google-cache-control': 'remote-fetch', 'vary': 'Origin', 'server': 'HTTP Upload Server Built on Jan 23 2014 15:07:07 (1390518427)', 'date': 'Sat, 08 Feb 2014 16:49:56 GMT', 'content-type': 'application/xml; charset=UTF-8'}.
Extra info: None.

, ( ) - , API Google - , , .

, Google 403 , urlfetch App Engine, , ( , , HTTP , , ). , .

, API? , , AccountProblem InvalidSecurity - . , API , , .

" " , . , , -, - . Gmail, , . ( URL-.)

+4
1

appengine .

" " appengine " ".

+4

Source: https://habr.com/ru/post/1525954/


All Articles