手机
当前位置:查字典教程网 >脚本专栏 >python >Python使用百度API上传文件到百度网盘代码分享
Python使用百度API上传文件到百度网盘代码分享
摘要:关于如何获取access_token这个可以自己查百度开放的OAuth2.0的API。这里不做介绍。第三方Python库poster复制代码...

关于如何获取 access_token 这个可以自己查百度开放的OAuth 2.0 的 API。这里不做介绍。

第三方 Python 库

poster

复制代码 代码如下:

# 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):

"""

通过百度开发者 API 上传文件到百度云

"""

datagen, headers = multipart_encode({"file": open("E:PHPTestTest1%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使用百度API上传文件到百度网盘代码分享】相关文章:

Python获取远程文件大小的函数代码分享

python定时器使用示例分享

Python中的文件和目录操作实现代码

python用ConfigObj读写配置文件的实现代码

python 图片验证码代码分享

python使用正则表达式检测密码强度源码分享

python批量修改文件后缀示例代码分享

python使用paramiko模块实现ssh远程登陆上传文件并执行

python使用PyV8执行javascript代码示例分享

python获取豆瓣电影简介代码分享

精品推荐
分类导航