b3nab / instapy-cli

:sparkles: Python library and CLI to upload photo and video on Instagram. W/o a phone!
MIT License
601 stars 98 forks source link

[BUG] OSError: Unable to Upload #75

Open dylan736 opened 5 years ago

dylan736 commented 5 years ago

I cannot upload to Instagram with InstaPy-CLI using unchanged python scripts which used to work just 2 days ago.

I have two files (master.py and exec.py). I run exec.py to carry out the functions in master.py.

Master.py:

import urllib.request
from PIL import Image, ImageOps
from instapy_cli import client
from datetime import date

def get_item_shop():
    url = "http://api2.nitestats.com/v1/shop/image?footer=USE%20CODE:%20%22DISTURBED%22"
    urllib.request.urlretrieve(url, "itemshop.jpg")

def resize():
    desired_size = 1728
    im_pth = "itemshop.jpg"

    im = Image.open(im_pth)
    old_size = im.size  # old_size[0] is in (width, height) format

    ratio = float(desired_size)/max(old_size)
    new_size = tuple([int(x*ratio) for x in old_size])
    # use thumbnail() or resize() method to resize the input image

    # thumbnail is a in-place operation

    # im.thumbnail(new_size, Image.ANTIALIAS)

    im = im.resize(new_size, Image.ANTIALIAS)
    # create a new image and paste the resized on it

    new_im = Image.new("RGB", (desired_size, desired_size), (30,30,30))
    new_im.paste(im, ((desired_size-new_size[0])//2,
                        (desired_size-new_size[1])//2))

    output_path = 'itemshop2.jpg'
    new_im.save(output_path)

def post():
    today = date.today()
    d2 = today.strftime("%B %d, %Y")

    heart = "\U00002764"

    username = 'fbr.itemshop'
    password = 'Albion0411'
    cookie_file = 'cookie.json'

    image = 'itemshop2.jpg'
    text = 'Daily item shop for ' + d2 +'.' + '\r\n' + '\r\n' + 'Rate this item shop from 1-10!' + '\r\n' + '\r\n' + 'Use code: "Disturbed" to support me! ' + heart + '\r\n' + '#fortnite #itemshop #dailyitemshop #fortniteitemshop'

    with client(username, password, cookie_file=cookie_file, write_cookie_file=True) as cli:

        cookies = cli.get_cookie()

        cli.upload(image, text)

Exec.py:

import master
import time

master.get_item_shop()
print("Item shop saved.")
time.sleep(5)
master.resize()
print("Image resized.")
time.sleep(5)
master.post()
print("Image posted.")

These scripts fetch the Fortnite Item Shop image from nitestats.com API, resizes it to 1:1 for IG, and uploads it. Saving the image and resizing still works, but posting to IG doesn't. As the item shop refreshes every day at 00:00 for me, I use crontab on my RPi to schedule the running of these python scripts. It has worked in the past, so I know crontab has no errors. However, I set crontab to write to a log so that I could see if anything went wrong. Below is what I got.

Logs

This is what is outputted to a log when the scripts are functioning:

Item shop saved.
Image resized.
[IG] not found cookie/cookie_file >> login as default
SAVED: COOKIE_FOR_USER.json
Done.
Image posted.

And, when they're not working:

Item shop saved.
Image resized.
[IG] re-use cookie from COOKIE_FOR_USER.json
Error is >>
    Bad Request

Something went bad.
Please retry or send an issue on https://github.com/b3nab/instapy-cli

Traceback (most recent call last):
  File "/home/pi/Downloads/ItemShopBot/exec.py", line 10, in <module>
    master.post()
  File "/home/pi/Downloads/ItemShopBot/master.py", line 57, in post
    cli.upload(image, text)
  File "/home/pi/.local/lib/python3.8/site-packages/instapy_cli/cli.py", line 153, in upload
    raise IOError("Unable to upload.")
OSError: Unable to upload.

Env (please complete the following information):

I have searched Google for this issue, and the only thing I could find was saying that Instagram have declined my request to upload. I have attempted to run the code on Windows, which gave the same issue, with and without a VPN, with different Instagram accounts, reset the passwords, and tried to use the scripts with and without the cookie file. I am fairly new to Python and would appreciate any help possible.

b3nab commented 3 years ago

@RomjanHossain You can try if you want. :D The project is deprecated, lots of spammers on instagram and no one supported me (collaborations, PRs or donations). So I'm not supporting the project anymore. 🥂

johnjreiser commented 3 years ago

@b3nab - I previously used this library for a project posting aerial photography to Instagram. Thank you for building it!

jx13xx commented 3 years ago

Hello there, I have actually debugged this issue .. turns out that Instagram has disabled their public API as of June 2020. Once if you check the code where the request is sent to the endpoint we actually get a 404 Not Found which is turning out to print the error "Unable to Upload Error" Your best option is to use Selenium or other resources for this automation