国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

Python使用百度API上傳文件到百度網(wǎng)盤代碼分享

2019-11-25 18:06:32
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

關(guān)于如何獲取 access_token 這個(gè)可以自己查百度開放的OAuth 2.0 的 API。這里不做介紹。

第三方 Python 庫(kù)

poster

復(fù)制代碼 代碼如下:

# 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):
    """
    通過(guò)百度開發(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")

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 上思县| 达孜县| 咸宁市| 赤壁市| 沧州市| 和政县| 盐池县| 禹州市| 遂昌县| 莱芜市| 治多县| 连南| 高淳县| 舞钢市| 山西省| 香河县| 西和县| 宣恩县| 沂水县| 通江县| 泰和县| 西安市| 海城市| 开远市| 德惠市| 汕尾市| 大港区| 竹北市| 东平县| 忻城县| 黄平县| 宁明县| 如皋市| 行唐县| 宽甸| 出国| 韶山市| 西乌| 保德县| 苏州市| 深州市|