ping / instagram_private_api

A Python library to access Instagram's private API.
MIT License
2.96k stars 615 forks source link

HTTP Error 400: Bad Request #171

Closed zykloner closed 5 years ago

zykloner commented 5 years ago

Please follow the guide below


Before submitting an issue, make sure you have:

Which client are you using?


Describe your issue

so i made a program to schedule uploading photos, and it was doing it once every 12 hours. In between every 2 hours it would like all profile feed and search for specific hastags to like around 70-80 images every 2 hours or so. It was working fine when all of a sudden Its started giving me error:400 bad request. I hope its not soft block or something because the code was working fine before this started happening.


Paste the output of python -V here:

Code:

# Example code that will produce the error reported
from instagram_private_api import Client, ClientCompatPatch
import json
import time
import os.path
import codecs
import base64
import schedule_post
import os
import image_resizers as imgzr
import hashtaglikes
import timemanager

def to_json(python_object):
    if isinstance(python_object, bytes):
        return {'__class__': 'bytes',
                '__value__': codecs.encode(python_object, 'base64').decode()}
    raise TypeError(repr(python_object) + ' is not JSON serializable')

def from_json(json_object):
    if '__class__' in json_object and json_object['__class__'] == 'bytes':
        return codecs.decode(json_object['__value__'].encode(), 'base64')
    return json_object

def LoginAcc():
 global api
 user_name = 'xxxx'
 password = 'xxxx'
 if os.path.isfile("settings.txt") : #this is where login details are saved. I detled it a few times tp checl if its due to expiry of cookies. But the same issue occurred.
     f=open("settings.txt","r")
     print ("Old Login")
     sett=json.load(f,object_hook=from_json)
     api = Client(user_name, password,settings=sett)
 else:
     api = Client(user_name, password)
     time.sleep(1)
     aax=api.settings
     print ("New Login")
     f=open("settings.txt","w")
     json.dump(aax ,f, default=to_json)

def hastag_like(tagss):
 rank_token = Client.generate_uuid()
 has_more = True
 tag_results = []
 #while rank_token:
 results = api.feed_tag(tagss, rank_token, exclude_list=[t['media_id'] for t in tag_results])
 posts = results.get('items', [])
 x=0
 for post in posts:
     # retrieve post data
     a=post.get('id')
     x=x+1
     print (str(a) +"  Post Liked")
     api.post_like(a, module_name='feed_timeline')
 print (str(x)+ "posts liked")

def LikeFeed():  
 results = api.feed_timeline()
 items = [item for item in results.get('feed_items', [])
 if item.get('media_or_ad')]
 for item in items:
  a=(item['media_or_ad']['id'])
  api.post_like(a, module_name='feed_timeline')
  print (a)

####Functions over########
while True:
    LoginAcc() #login with cache or not
    hastag_like("cats")
    LikeFeed()
    timemanager.update_date()

    if timemanager.check_date()>(12): # total hours from last upload
     cur_dir=os.path.dirname(os.path.abspath(__file__))
     imagevals=timemanager.dats[0]
     print (str(imagevals) + " Is the current posting index")
     pathe=cur_dir+"/data/"+str(imagevals)+".jpeg"
     imgzr.insta_resize(pathe)
     strss=open(pathe, "rb") 
     captionss=schedule_post.find_caption(imagevals)
     imgzr.insta_resize(pathe)
     api.post_photo(photo_data=strss.read(),caption=captionss,size=(600,600),upload_id=None, to_reel=False)
     timemanager.write_date()
    time.sleep(5000)

Error/Debug Log:

Old Login
Traceback (most recent call last):
  File "../instagram_private_api/client.py", line 523, in _call_api
    response = self.opener.open(req, timeout=self.timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.5/urllib/request.py", line 510, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../main.py", line 72, in <module>
    LikeFeed()
  File ".../main.py", line 64, in LikeFeed
    api.post_like(a, module_name='feed_timeline')
  File ".../instagram_private_api/endpoints/media.py", line 360, in post_like
    res = self._call_api(endpoint, params=params, query={'d': '1'})
  File ".../instagram_private_api/client.py", line 527, in _call_api
    ErrorHandler.process(e, error_response)
  File ".../Instabot/instagram_private_api/errors.py", line 135, in process
    raise ClientError(error_msg, http_error.code, error_response)
instagram_private_api.errors.ClientError: Bad Request: feedback_required
dvingerh commented 5 years ago

The answer lies here:

instagram_private_api.errors.ClientError: Bad Request: feedback_required

It's likely because you're hitting the API limits. You can find similar reports about this around Github.

zykloner commented 5 years ago

Hey thanks. Is there a known api safe limit ?

dvingerh commented 5 years ago

I'm not aware of any known safe limits, but the general rule of thumb is to not deviate from mimicking normal user behavior.

You're liking a large amount of pictures in a short time which would be considered bot/spam like activity, something this repo owner definitely doesn't support.

zykloner commented 5 years ago

ok i'll distribute the likes in the 2 hours with random intervals in between to make it look more human.

zykloner commented 5 years ago

Was the ban. Got lifted in 12 hours. I couldn't even like posts from official app during tge period and a message regarding then trying to protest the community poped up. I have severely limited the number of posts it makes and likes so as to not get flagges again.