Python使用百度API上传文件到百度网盘代码分享
作者:junjie 时间:2023-08-05 02:38:52
关于如何获取 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:\\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")


猜你喜欢
Go语言实现钉钉发送通知
python淘宝准点秒杀抢单的实现示例

Java正则表达式Pattern和Matcher原理详解
Python命令行参数解析包argparse的使用详解

浅谈Python中os模块及shutil模块的常规操作
python读取oracle函数返回值

解决Python中回文数和质数的问题

Django restful framework生成API文档过程详解

通过实例解析Python调用json模块
解析ASP与SQL server互操作的时间处理
vue基于input实现密码的显示与隐藏功能

实现PHP多线程异步请求的3种方法
python中删除某个元素的方法解析
详解如何在微信小程序开发中正确的使用vant ui组件

卷积神经网络的发展及各模型的优缺点及说明

MYSQL中 TYPE=MyISAM 错误的解决方法
在Windows服务器下用Apache和mod_wsgi配置Python应用的教程
如何通过Vue实现@人的功能
