python 网络文件传输(邮件+百度网盘(百度云盘)+阿里云盘)

邮件(以QQ邮箱为例)

发件人开启POP3/SMTP

  • 邮箱设置->账户(新版本的在常规中)->POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务
    在这里插入图片描述
  • 有的账号登陆后是这个界面(在常规中寻找就行了)
    ps:发现了邮件“**** 是你的 Twitter 验证码"可能是Twitter系统反应太慢了?我当时好像没有收到验证的消息。
    zwwgzjznwvgjcjic

import os
import smtplib # SMTP(Simple Mail Transfer Protocol)简单邮件传输协议
# 支持发送的类型:MIMEApplication(各种类型),MIMEAudio,MIMEImage,MIMEMessage, MIMEText
from email.mime.application import MIMEApplication
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


from_mail = '----------@qq.com'    #发件人邮箱
to_mails = '---------@qq.com'     #收件人邮箱,添加多个收件人,中间用','隔开
mail_pass = '------'    #授权码
# 三个参数:第一个为文本内容,第二个 plain 设置文本格式,第三个 utf-8 设置编码
msg = MIMEText(
    """编写邮件内容,
        本内容用的是'plain'
        也可以使用'html'格式
        SMTP(Simple Mail Transfer Protocol)
        smtplib.SMTP( [host [, port [, local_hostname]]] )
    """, "plain", "utf-8")
content_part = msg

m = MIMEMultipart()
m.attach(content_part)  #添加邮件正文内容
m['Subject'] = '标题' #邮件主题
m['From'] = from_mail   #发件人
m['To'] = to_mails    #收件人

# attach file
# for img_index in os.listdir("./img"):
#     print(img_index)
#     imageFile = r'.//img//'+img_index
#     image = MIMEImage(open(imageFile, 'rb').read(), _subtype='octet-stream')
#     image.add_header('Content-Disposition', 'attachment', filename=img_index)
#     m.attach(image)
# 或使用MIMEApplication
for img_index in os.listdir("./img"):
    print(img_index)
    imageFile = r'.//img//'+img_index
    image = MIMEApplication(open(imageFile, 'rb').read(), _subtype='octet-stream')
    image.add_header('Content-Disposition', 'attachment', filename=img_index)
    m.attach(image)

try:
    server = smtplib.SMTP('smtp.qq.com') # 创建 SMTP 对象
    # 登陆邮箱(参数1:发件人邮箱,参数2:邮箱授权码)
    server.login(from_mail, mail_pass)
    # 发送邮件(参数1:发件人邮箱,参数2:若干收件人邮箱,参数3:把邮件内容格式改为str)
    server.sendmail(from_mail, to_mails.split(','), m.as_string()) # SMTP 对象使用 sendmail 方法发送邮件
    print('success')
    server.quit()
except smtplib.SMTPException as e:
    print('error:', e)  

百度网盘

  • pip install requests bypy -i https://pypi.douban.com/simple
(venv) C:\Users\admin\Desktop\pyworkspace\em>pip install requests bypy -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple
Collecting requests
  Downloading https://pypi.doubanio.com/packages/41/5b/2209eba8133fc081d3ffff02e1f6376e3117e52bb16f674721a83e67e68e/requests-2.28.0-py3-none-any.whl (62 kB)
     ---------------------------------------- 62.8/62.8 kB 559.7 kB/s eta 0:00:00
Collecting bypy
  Downloading https://pypi.doubanio.com/packages/1d/f4/446a7e6bff90b9f6628648d949bf161826233ebb681ad5d5bda3f2bf4762/bypy-1.7.12-py2.py3-none-any.whl (241 kB)
     ---------------------------------------- 241.7/241.7 kB 568.8 kB/s eta 0:00:00
Collecting certifi>=2017.4.17
  Downloading https://pypi.doubanio.com/packages/11/dd/e015f3780f42dd9af62cf0107b44ea1298926627ecd70c17b0e484e95bcd/certifi-2022.5.18.1-py3-none-any.whl (155 kB)
     ---------------------------------------- 155.2/155.2 kB 579.7 kB/s eta 0:00:00
Collecting charset-normalizer~=2.0.0
  Downloading https://pypi.doubanio.com/packages/06/b3/24afc8868eba069a7f03650ac750a778862dc34941a4bebeb58706715726/charset_normalizer-2.0.12-py3-none-any.whl (39
kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading https://pypi.doubanio.com/packages/ec/03/062e6444ce4baf1eac17a6a0ebfe36bb1ad05e1df0e20b110de59c278498/urllib3-1.26.9-py2.py3-none-any.whl (138 kB)
     ---------------------------------------- 139.0/139.0 kB 590.6 kB/s eta 0:00:00
Collecting idna<4,>=2.5
  Downloading https://pypi.doubanio.com/packages/04/a2/d918dcd22354d8958fe113e1a3630137e0fc8b44859ade3063982eacd2a4/idna-3.3-py3-none-any.whl (61 kB)
     ---------------------------------------- 61.2/61.2 kB 462.9 kB/s eta 0:00:00
Collecting requests-toolbelt
  Downloading https://pypi.doubanio.com/packages/60/ef/7681134338fc097acef8d9b2f8abe0458e4d87559c689a8c306d0957ece5/requests_toolbelt-0.9.1-py2.py3-none-any.whl (5
4 kB)
     ---------------------------------------- 54.3/54.3 kB 710.9 kB/s eta 0:00:00
Collecting multiprocess
  Downloading https://pypi.doubanio.com/packages/1e/bc/625b7345861101ef708a0d5b4e9fd7694e2f97621a69e9b869100e0be47d/multiprocess-0.70.13-py38-none-any.whl (131 kB)

     ---------------------------------------- 131.4/131.4 kB 644.6 kB/s eta 0:00:00
Collecting dill>=0.3.5.1
  Downloading https://pypi.doubanio.com/packages/12/ff/3b1a8f5d59600393506c64fa14d13afdfe6fe79ed65a18d64026fe9f8356/dill-0.3.5.1-py2.py3-none-any.whl (95 kB)
     ---------------------------------------- 95.8/95.8 kB 785.2 kB/s eta 0:00:00
Installing collected packages: urllib3, idna, dill, charset-normalizer, certifi, requests, multiprocess, requests-toolbelt, bypy
Successfully installed bypy-1.7.12 certifi-2022.5.18.1 charset-normalizer-2.0.12 dill-0.3.5.1 idna-3.3 multiprocess-0.70.13 requests-2.28.0 requests-toolbelt-0.9.1
 urllib3-1.26.9

  • bypy -h # 帮助

  • bypy info

(venv) C:\Users\admin\Desktop\pyworkspace\em>bypy info
<W> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
<W> You are running Python on Windows, which doesn't support Unicode so well.
Files with non-ASCII names may not be handled correctly.
<W> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
<W> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
<W> WARNING: System locale is not 'UTF-8'.
Files with non-ASCII names may not be handled correctly.
You should set your System Locale to 'UTF-8'.
Current locale is 'cp936'
<W> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
Please visit:
https://openapi.baidu.com/oauth/2.0/authorize?client_id=*********&response_type=code&redirect_uri=oob&scope=basic+netdisk
And authorize this app
Paste the Authorization Code here within 10 minutes.
Press [Enter] when you are done

在这里插入图片描述
在这里插入图片描述

  • 复制授权码,粘贴,enter
Authorizing, please be patient, it may take upto 300 seconds...
Authorizing with the Vercel server ...
Successfully authorized
  • bypy upload test.txt -v # 若 bypy upload -v 则为上传当前文件夹

  • bypy list #查看文件

/apps/bypy ($t $f $s $m $d):
F test.txt 0 2022-06-16, 14:31:58 8e23f7635t*********
  • bypy downdir / # 下载远程文件到当前文件夹
 [14:43:20] test.txt <- /apps/bypy/test.txt
[====================] 100% (0.0B/0.0B)
  • bypy downdir / test # 下载文件到test文件夹

  • bypy -c #取消授权

阿里云盘

  • aligo v4.6.6 不兼容python 3.8
    在这里插入图片描述

参考与更多

# 百度云盘
https://github.com/houtianze/bypy
# 有关阿里云盘
https://blog.51cto.com/u_15127650/4660863
https://github.com/foyoux/aligo
# 发送邮件
https://blog.csdn.net/weixin_46473347/article/details/107816491
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值