GoogleCloudPlatform / appengine-gcs-client

App Engine-Cloud Storage custom client library
Apache License 2.0
124 stars 112 forks source link

Does Not Work On Python Dev Server #54

Open bmayfi3ld opened 7 years ago

bmayfi3ld commented 7 years ago

Trying to use the python client library with the development server. Each time I try to write to the bucket I get this error:

It works fine when deployed on app engine

ServerError: Expect status [201] from Google Storage. But got status 500.
Path: '/*****mybucket******/7jj601gxnc20160925124634jpgdl0.jpg'.
Request headers: {'content-type': 'image/jpeg', 'accept-encoding': 'gzip, *', 'x-goog-api-version': '2', 'x-goog-resumable': 'start'}.
Response headers: {'server': 'Development/2.0', 'date': 'Sat, 26 Nov 2016 17:48:14 GMT', 'transfer-encoding': 'chunked'}.
Body: ''.
Extra info: None.

my python code, pretty much taken directly from https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/read-write-to-cloud-storage

abbreviated version

 bucket_name = os.environ.get('BUCKET_NAME',
                               app_identity.get_default_gcs_bucket_name())
   file_name = slugify(request.args.get('pic'), separator = '')[24:] + '.jpg'
    bucket_file = '/{}/{}'.format(bucket_name, file_name) #generally turns into something like /app_default_bucket/7jj6012fnc20250925124634jpgdl0.jpg' on the development server

write_retry_params = gcs.RetryParams(backoff_factor = 1.1)
gcs_file = gcs.open(bucket_file, 'w', 'image/jpeg', retry_params = write_retry_params)
out_string.seek(0) # StringIO object
gcs_file.write(out_string.getvalue())
gcs_file.close()

As I mentioned works perfectly when deployed.

Something else I discovered I can get it to give me a 404 not found error if I just try to open random files.

birdchan commented 5 years ago

Is this resolved? I have the same issue...

Rob1080 commented 5 years ago

@birdchan did you find a fix for this issue? Just started happening in one of my projects now too.

birdchan commented 5 years ago

If I remember correctly, it has something to do with the credential json file, giving bucket read/write access to that service account at the IAM portal. The app engine app once deployed has a default service account, which may be different from the service account you have in your local credential json file.

Rob1080 commented 5 years ago

@birdchan thanks for responding. I found this issue https://issuetracker.google.com/issues/35900575 (and monkey patch fix) had been reported which seemed to be the problem I was having.