简体   繁体   English

*** ConnectionError:尝试将文件上传到Google Cloud Storage时(“连接已中止。”,错误(13,“权限被拒绝”))

[英]*** ConnectionError: ('Connection aborted.', error(13, 'Permission denied')) when trying to upload files to Google Cloud Storage

I am testing my app using dev_appserver.py . 我正在使用dev_appserver.py测试我的应用程序。

My function to upload files looks something like: 我上传文件的功能如下所示:

def upload_file(file_stream, filename):
    """Upload a file to Google Cloud Storage."""

    client = google.cloud.storage.client.Client(project=_GOOGLE_CLOUD_PROJECT)
    bucket = client.get_bucket(_GOOGLE_STORAGE_BUCKET)  # Here it breaks!

    blob = bucket.blob(filename)
    blob.upload_from_string(file_stream)

    url = blob.public_url

    return url

At the line bucket = client.get_bucket(_GOOGLE_STORAGE_BUCKET) I receive an error saying: bucket = client.get_bucket(_GOOGLE_STORAGE_BUCKET)我收到一条错误消息:

*** ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))

I authenticated by doing: 我通过以下方式进行了身份验证:

gcloud auth application-default login

My app.yaml: 我的app.yaml:

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /static
  static_dir: static
  application_readable: true
- url: /.*
  script: main.app

libraries:
- name: ssl
  version: latest

Any idea how to solve? 知道如何解决吗?

It seems that you have not set the proper permissions to access your Cloud Storage bucket from the account you are using to run your app. 似乎您没有设置适当的权限来从用于运行应用程序的帐户访问Cloud Storage存储桶。

The bucket' permissions are set through the use of Access Control Lists (ACLs), which define which accounts can access to the bucket and the kind of access (read, write, etc.) they have. 存储桶的权限是通过使用访问控制列表 (ACL)设置的, 访问控制列表定义了哪些帐户可以访问该存储桶以及它们具有的访问类型(读取,写入等)。

This is an example on how to set permissions to a particular account so it can access a bucket: 这是有关如何为特定帐户设置权限以使其可以访问存储桶的示例:

gsutil acl ch -u [USER_EMAIL]:[PERMISSION] gs://[BUCKET_NAME]

There are other available options for setting ACLs, like using the Console or adding permissions through your code. 还有其他可用选项可用于设置ACL,例如使用控制台或通过代码添加权限。 You can find these options here . 您可以在此处找到这些选项。

UPDATE : 更新

After doing some research and consulting with the team handling this kind of situations, I can confirm that the use of SSL with sockets is not supported on dev_appserver as of this moment. 在进行了一些研究并咨询了处理此类情况的团队之后,我可以确认到目前为止,dev_appserver不支持将SSL与套接字一起使用 As the client library you are using is using HTTPS for connections, without this support, using dev_appserver would not work. 由于您正在使用的客户端库使用HTTPS进行连接,如果没有此支持,则无法使用dev_appserver。

As an alternative, you may consider using the API client library for Python . 或者,您可以考虑使用适用于PythonAPI客户端库 Here you can find an example on how to use this library to connect to a Cloud Storage bucket from your app. 在这里,您可以找到有关如何使用此库从您的应用程序连接到Cloud Storage存储桶的示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App Engine - ConnectionError :('连接已中止。',错误(13,'权限被拒绝')) - Google App Engine - ConnectionError: ('Connection aborted.', error(13, 'Permission denied')) python-twitter,Google应用引擎,(“连接已中止。”,错误(13,“权限被拒绝”)) - python-twitter, google app engine, ('Connection aborted.', error(13, 'Permission denied')) 我如何解决Django AllAuth - '连接中止。',错误(13,'权限被拒绝')错误? - How do I resolve Django AllAuth - 'Connection aborted.', error(13, 'Permission denied') Error? pip 安装失败,ProtocolError('Connection aborted.', PermissionError(13, 'Permission denied')) - pip install fails with ProtocolError('Connection aborted.', PermissionError(13, 'Permission denied')) msg:ConnectionError(ProtocolError('Connection aborted。',error(2,'No such file or directory')),) - msg: ConnectionError(ProtocolError('Connection aborted.', error(2, 'No such file or directory')),) Python Spider ConnectionError :(“连接已中止。”,BadStatusLine(“''”,)) - Python Spider ConnectionError: ('Connection aborted.', BadStatusLine(“''”,)) HTTP:错误:ConnectionError :(对URL进行POST请求时,“连接已终止。”,错误(32,“管道损坏”)): - http: error: ConnectionError: ('Connection aborted.', error(32, 'Broken pipe')) while doing POST request to URL: 当xml大小增加时,Python请求XML API异常ConnectionError :(“连接已中止。”,BadStatusLine(“''”,)) - Python Requests XML API Exception ConnectionError: ('Connection aborted.', BadStatusLine(“''”,)) when xml size increases 请求超时错误 (requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))) - Requests Timeout Error (requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))) Firebase 存储文件上传“连接中止”。 错误 - Firebase Storage file uploading 'Connection aborted.' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM