python - 使用 instapy-cli 库防止 python 脚本使用 try/except 崩溃
问题描述
我正在使用一个发布到 instagram (instapy-cli) 的 python 库。但是,这将用于安装,如果 wifi 中断,即使上传不起作用,我仍然希望脚本运行。我已经将它包装在 try/except 中,但如果函数崩溃,它仍然会结束脚本。
这是我的代码
try:
with client(username,password) as cli:
cli.upload(fileName, text)
except Exception as e:
print(e.output)
在控制台中,我得到下面提到的错误:
ClientError URLError urlopen 错误 [Errno 11001] getaddrinfo failed>(代码:0,响应:)
在我有代码之前:
try:
subprocess.call([r'filePath/insta.bat', fileName, caption])
except subprocess.CalledProcessError as e:
print(e)
完全按照我的意愿工作(如果没有wifi,脚本会继续运行并且它会默默地失败)
解决方案
我挖掘了库 instapy-cli 的源代码,在上传函数中发现:
except ClientLoginError as e:
print('ClientLoginError {0!s}'.format(e))
exit(9)
所以我分叉了 repo,注释掉了退出函数,卸载了库,然后重新安装了我的分叉版本。像魅力一样工作!
推荐阅读
- loops - RN FlatList 循环变量
- powershell - Invoke-WebRequest :远程服务器返回错误:(500)内部服务器错误
- arrays - 在 bash 中同时迭代三个数组
- php - 基于独占值获取结果:mysql & laravel
- javascript - 套接字正在创建单个实例。如何从多个客户端创建此应用程序?
- android - 如何识别特定文本并将该文本替换为android中图像内的其他文本?
- c# - 使用c#将日期时间插入oracle数据库
- android - 无法使用 cmd 构建 android 项目
- python - 正则表达式不返回结果
- javascript - 星级CSS问题