【问题标题】:Can't upload some photos to instagram by instabot无法通过 instabot 将某些照片上传到 instagram
【发布时间】:2020-09-14 00:59:13
【问题描述】:

我无法使用 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 - 错误 - 照片上传失败,响应如下: 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 图像编辑同一张图片,但也没有用

基本上,我希望您能提供帮助,谢谢!

【问题讨论】:

    标签: python python-imaging-library instagram


    【解决方案1】:

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

    new_im = new_im.convert("RGB")
    

    【讨论】:

    • 这行得通!你能否简要解释一下你为什么这样做以及你是如何知道这个解决方案的?文档中有任何内容吗?
    • 对不起,迟了 7 个月的回复,但幸运的是你让我如此痛苦,我仍然记得一切。基本上找不到有关该主题的文档,我不得不继续测试和分析一个多月,直到找到解决方案。因为我知道当我将照片上传到网站并以 JPEG 格式再次下载时,它确实会正常上传到 Instagram,之后我的主要目标是将其转换为 JPEG。我测试了许多其他荒谬的事情,但我在这里所说的是实际上让我更接近解决方案。
    • 非常感谢!你也救了我至少 7 个月!我首先尝试将文件扩展名简单地编辑为 .jpeg,但这不起作用。将其保存为 .jpeg 就像一个魅力!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多