阿里云oss初使用

一、购买

二、配置RAM权限

https://ram.console.aliyun.com/users

1、创建用户

 

 

2、创建完成后注意获取AccessKey ID、AccessKey Secret(只展示一次,后面会用到)

3、添加权限,这里全部权限都添加上(我也没有仔细看,选中前面几个,后面就默认全选了)

 

 

 

 

 

 三、创建Bucket 

https://oss.console.aliyun.com/bucket

 

 

 

 

四、安装对应的SDK

1、找到对应的SDK

https://help.aliyun.com/document_detail/32006.html

 

 

 2、选择对应的语言(这里使用Python)

 

 

 3、安装SDK

 

 

 4、操作案例,按提示填写对应的信息,新建python文件

 

五、运行时的一个报错

oss2.exceptions.RequestError: {'status': -2, 'x-oss-request-id': '', 'details': "RequestError: HTTPSConnectionPool(host='laat.oss-cn-beijin.aliyuncs.com', port=443): Max retries exceeded with url: /exampleobject.txt (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa8864b2320>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))"}
/Users/sunxinyang/Desktop/LaatUI/venv/bin/python /Users/sunxinyang/Desktop/LaatUI/LaatUI/apps/reports/views.py
Traceback (most recent call last):
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/urllib3/connection.py", line 175, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/urllib3/util/connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 710, in urlopen
    chunked=chunked,
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 1040, in _validate_conn
    conn.connect()
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/urllib3/connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/urllib3/connection.py", line 187, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fa8864b2320>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/requests/adapters.py", line 450, in send
    timeout=timeout
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 786, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='laat.oss-cn-beijin.aliyuncs.com', port=443): Max retries exceeded with url: /exampleobject.txt (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa8864b2320>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/oss2/http.py", line 49, in do_request
    proxies=req.proxies))
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='laat.oss-cn-beijin.aliyuncs.com', port=443): Max retries exceeded with url: /exampleobject.txt (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa8864b2320>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sunxinyang/Desktop/LaatUI/LaatUI/apps/reports/views.py", line 14, in <module>
    result = bucket.put_object('exampleobject.txt', 'Hello OSS')
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/oss2/api.py", line 567, in put_object
    resp = self.__do_object('PUT', key, data=data, headers=headers)
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/oss2/api.py", line 2529, in __do_object
    return self._do(method, self.bucket_name, key, **kwargs)
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/oss2/api.py", line 227, in _do
    resp = self.session.do_request(req, timeout=self.timeout)
  File "/Users/sunxinyang/Desktop/LaatUI/venv/lib/python3.6/site-packages/oss2/http.py", line 51, in do_request
    raise RequestError(e)
oss2.exceptions.RequestError: {'status': -2, 'x-oss-request-id': '', 'details': "RequestError: HTTPSConnectionPool(host='laat.oss-cn-beijin.aliyuncs.com', port=443): Max retries exceeded with url: /exampleobject.txt (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa8864b2320>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))"}

Process finished with exit code 1
View Code

解决方案:

安装如下插件

pip install cryptography

pip install pyOpenSSL

pip install certifi

 

posted @ 2022-03-17 17:48  Delta.Farce  阅读(1564)  评论(0编辑  收藏  举报