无法将某些照片通过instabot上传到instagram

时间:2020-09-12 20:22:06

标签: python python-imaging-library instagram

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

我使用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-错误-图片上传失败,并显示以下响应:<响应[400]> 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图像编辑同一张图片,但这也行不通

基本上,这就是我希望您能提供的全部,谢谢!

1 个答案:

答案 0 :(得分:0)

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

new_im = new_im.convert("RGB")
相关问题