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脚本pic_upload.py实现图片上传的过程,使用了progressbar和baidupcsapi库,定义了进度条类。还说明了在虚拟环境pi_py3下运行该脚本,运行时需输入图片验证码和邮箱数字验证码。

被折叠的 条评论
为什么被折叠?



