Skip to content

Instantly share code, notes, and snippets.

@bestony
Created March 5, 2020 02:38
Show Gist options
  • Save bestony/5d6095b9c1fea968ef65710f3b0b098a to your computer and use it in GitHub Desktop.
Save bestony/5d6095b9c1fea968ef65710f3b0b098a to your computer and use it in GitHub Desktop.
云开发上传
# Install the Python Requests library:
# `pip install requests`
import requests
def send_request():
# 上传文件
# POST https://cos.ap-shanghai.myqcloud.com/7263-rcn-1258788140/testfile
try:
response = requests.post(
url="https://cos.ap-shanghai.myqcloud.com/7263-rcn-1258788140/testfile",
headers={
"Content-Type": "multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__",
},
files={
"file": "123",
"x-cos-meta-fileid": "HBPXgrO3M5Wijh6eLuVVX+iG11rk4mNdQum5Lg10PFCDuk7sQN12Y4t0fG36qkajY6iZGe3GSIo/5ykMG4hdsu1HUJ5OZccS7VA4961UZiJ27pOrXRBtgxYjssuMW52+pyXLIO0sYHvHCQn8EZE=",
"x-cos-security-token": "oKPjfeWGvRFzSR45azxJoZEzcMozJOWecd700261215792a61eefe56427ac91f6OlXUai4_iST1mbzYo8ph_GCgGejJNvtA1V483_SpzpnsPLeQc43b1MKj3yI5Dr0zT-jfYFB33-fe52ZMdZhEl3dCuJN7buFKPOAQqwEjFlr7gSyOrP5ox350qslAnjKHxORAQVNMR3PwiA1uxMe3tjtOjQKTF-xu1kxTowczdtwPYYC7F-IqbQFZ9q_yIQGNzIKs_-67tIeLl0Zv7iUkCE3KcmJUG9isgjpnCe_BSUsgw6EvBmrYU7eP-AIPuFPJZyC7Ocum11PGr3H4HU2QuZYp1AOWI48izl2wSJyu3CZZGxjsZ2CNHomNw7KvGKvR3OISx74Zzr41mZc7P6RNYPzK6jeE3K3rwWuolKtaqnlPiUQLd9i_9HScv2xBbgD4MHwGZB6jgb3DgYlenCtFlQ",
"Signature": "q-sign-algorithm=sha1&q-ak=AKIDtxMKuQ9CIgWF-aSrFKfNzPpijPhLSYQ8q-fsI2KfFqA104Sba16xKmbT6RgYpHD-&q-sign-time=1581727591;1581728491&q-key-time=1581727591;1581728491&q-header-list=&q-url-param-list=&q-signature=62f0d5f90dec5153a59b28820f77255aa9baa37e",
"key": "testfile",
},
)
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))
print('Response HTTP Response Body: {content}'.format(
content=response.content))
except requests.exceptions.RequestException:
print('HTTP Request failed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment