admin管理员组

文章数量:1652184

2、编写一个脚本实现长传图片,命名为:pic_upload.py

import progressbar

from baidupcsapi import PCS

class ProgressBar():

def __init__(self):

self.first_call = True

def __call__(self, *args, **kwargs):

if self.first_call:

self.widgets = [progressbar.Percentage(), ' ', progressbar.Bar(marker=progressbar.RotatingMarker('>')),

' ', progressbar.ETA()]

self.pbar = progressbar.ProgressBar(widgets=self.widgets, maxval=kwargs['size']).start()

self.first_call = False

if kwargs['size'] <= kwargs['progress']:

self.pbar.finish()

else:

self.pbar.update(kwargs['progress'])

pcs = PCS('杜如意8','dxy199113')

test_file = open('example_04.jpg','rb').read()

ret = pcs.upload('/',test_file,'example_04.jpg',callback=ProgressBar())

3、在虚拟环境pi_py3环境下运行:

python3 pic_upload.py

要输入图片的验证码,还要接收邮箱的数字验证码,有些麻烦

本文标签: 文件上传方式百度网Python