python - 无法通过 instabot 将一些照片上传到 instagram

标签 python python-imaging-library instagram

我无法使用 instabot 将一些照片上传到 Instagram。 有些图片可以正常上传,有些则不能。我无法上传的是我使用“Pillow”编辑的那些。这是我的代码,之后我将向您展示我的尝试。

我使用 Pillow 的照片编辑功能:

def make_square(im, min_size=1080, fill_color=(255, 255, 255)):
    #here getting the width and the height of the picture and after that adjusting it's size for it to fit on a 1080px picture perfectly
    width, height = im.size
    ratio = 1080 / width
    width = width + 0.00
    height = height + 0.00
    width = width * ratio
    height = height * ratio
    height = math.floor(height)
    width = math.floor(width)
    im = im.resize((width, height)) #resizing the picture to width 1080
    #here is some code i got online to create a white picture then paste my picture on top of it to make the picture square
    x, y = im.size
    size = max(min_size, x, y)
    new_im = Image.new('RGBA', (size, size), fill_color)
    new_im.paste(im, (int((size - x) / 2), int((size - y) / 2)))
    return new_im # returning the new image so that I can save and upload

这是我将图片上传到 instagram 的另一个功能:

from instabot import Bot
def UPhoto(Image, Caption):
    bot = Bot()
    bot.login(username = "username", password="password")
    time.sleep(0.2)
    try:
        if bot.upload_photo(Image, caption=Caption):
            return True
        else:
            return False
    except:
        return False

当我运行上传照片时出现此错误:

找到:w:1080 h:1080 r:1.0 2020-09-12 16:00:53,680 - 错误 - 照片上传失败,响应如下: 2020-09-12 16:00:53,682 - 信息 - 照片“Post.png”未上传。 2020-09-12 16:00:53,683 - 信息 - 请求总数:54

我尝试过的:

  • 我尝试使用 whatsapp 将照片发送到我的手机并使用我的手机将其发布到 instagram 并且成功了
  • 我尝试将照片上传到 whatsapp 然后下载它,它下载为 jpeg,然后我尝试将它发布到 instagram 并且成功了
  • 我尝试更改文件扩展名并上传,但没有成功
  • 我尝试按原样上传图片,但没有使用 Pillow 对其进行编辑,它对一些人和其他人有效,而不取决于照片尺寸是否被 instagram 接受
  • 我试过复制图片然后发布,但没有成功
  • 我尝试用 scikit image 编辑同一张图片,但那也行不通

基本上这就是我希望你能提供的帮助,谢谢!

最佳答案

解决了! 将图像转换为“JPEG”,一切都很好。 使用:

new_im = new_im.convert("RGB")

关于python - 无法通过 instabot 将一些照片上传到 instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63864611/

相关文章:

Python "push server"TCP 客户端

python - Django 中图像/头像的自定义保存方法 - 如何使用

python - ImageFont 检测缺失字形(Python Pillow)

python - ValueError:形状不匹配:无法将对象广播到单个形状

python - Pandas 数据透视表 - 通过合并列的划分创建附加列

python - 从非常大的列表中排除特定值的平均值

python - 使用 Python Imaging Library 隔离单个 channel

python - 从 Instagram 句柄中提取媒体时出现错误 "Unable to parse response, not valid JSON"

javascript - Instagram embeds.js 库未加载

javascript - 用于 HTTPS 回调的 Instagram API