阿里雲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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM