Python使用百度API上傳文件到百度網(wǎng)盤代碼分享
關于如何獲取 access_token 這個可以自己查百度開放的OAuth 2.0 的 API。這里不做介紹。
第三方 Python 庫
# 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):
"""
通過百度開發(fā)者 API 上傳文件到百度云
"""
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")
相關文章
Python統(tǒng)計分析模塊statistics用法示例
這篇文章主要介紹了Python統(tǒng)計分析模塊statistics用法,結合實例形式分析了Python統(tǒng)計分析模塊statistics計算平均數(shù)、中位數(shù)、出現(xiàn)次數(shù)、標準差等相關操作技巧,需要的朋友可以參考下2019-09-09Python命令行參數(shù)解析模塊optparse使用實例
這篇文章主要介紹了Python命令行參數(shù)解析模塊optparse使用實例,本文講解了增加選項(add_option())、行為(action)、設置默認值(default)、生成幫助提示(help)、設置boolean值、錯誤處理、選項組(Grouping Options)等內(nèi)容,需要的朋友可以參考下2015-04-04python+pytest接口自動化參數(shù)關聯(lián)
這篇文章主要介紹了python+pytest接口自動化參數(shù)關聯(lián),參數(shù)關聯(lián),也叫接口關聯(lián),即接口之間存在參數(shù)的聯(lián)系或依賴,更多相關內(nèi)容需要的小伙伴可可以參考一下2022-06-06利用matplotlib實現(xiàn)根據(jù)實時數(shù)據(jù)動態(tài)更新圖形
今天小編就為大家分享一篇利用matplotlib實現(xiàn)根據(jù)實時數(shù)據(jù)動態(tài)更新圖形,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12