title: google-cloud-storage permission denied in google-app-engine standard
body: <p>Trying to access google cloud storage bucket from inside google app engine standard running flask using the <a href="https://googlecloudplatform.github.io/google-cloud-python/stable/index.html" rel="nofollow noreferrer">client library for Python</a> . </p>
  
  <p>(<strong>edit</strong>) not officially supported. see answer for workaround.</p>
  
  <p>code looks something like this..</p>
  
  <pre><code>from flask import Flask
  from google.cloud import storage
  
  # UNCOMMENT THIS FOR SOLUTION
  #import requests_toolbelt.adapters.appengine
  #requests_toolbelt.adapters.appengine.monkeypatch()
  
  app = Flask(__name__)
  @app.route('/endpoint', methods=['POST', 'PUT'])
  def upload_to_storage():
      try:
  
        # file info
        filename = secure_filename(file.filename)
        mimetype = file.content_type
  
        # connect to bucket
        client = storage.Client(project='projectName')
        bucket = client.get_bucket('bucketName')
  
        # upload file to bucket
        blob = storage.Blob(filename, bucket)
        blob.upload_from_file(file, content_type=mimetype, num_retries=10)
  
        return jsonify({'status':200})
  
      except:
  
        return jsonify({'status':500})
  </code></pre>
  
  <p>error message:</p>
  
  <p>('Connection aborted.', error(13, 'Permission denied'))</p>