about how to get access_token this can own check Baidu Open OAuth 2.0 API. There is no introduction here.
Third party Python Library
Poster
Copy Code code as follows:
# Coding:utf-8
Import Urllib
Import Urllib2
__author__ = ' Administrator '
From Poster.encode import Multipart_encode
From poster.streaminghttp import register_openers
Register_openers ()
def upload (fileName):
"""
Through Baidu developer API upload file to Baidu Cloud
"""
DataGen, headers = Multipart_encode ({"File": Open ("e:\\phptest\\test1\\%s"%filename, "RB")})
BaseURL = "Https://pcs.baidu.com/rest/2.0/pcs/file?"
args = {
"Method": "Upload",
"Access_token": "0.a2834e35964a7b0704242wef160507c1.2592000.1386326697.1060338330-1668780",
"Path": "/apps/resourcesharing/%s"%filename
}
Encodeargs = Urllib.urlencode (args)
url = baseurl + Encodeargs
Print (URL)
Request = Urllib2. Request (URL, DataGen, headers)
result = Urllib2.urlopen (request). Read ()
Print (Result)
Upload ("Host.txt")