ohld / igbot

🐙 Free scripts, bots and Python API wrapper. Get free followers with our auto like, auto follow and other scripts!
https://hikerapi.com/p/N2P6iqiM
Apache License 2.0
4.71k stars 1.47k forks source link

Update devices and headers to avoid 400 error or being banned #562

Closed alberdonpi closed 6 years ago

alberdonpi commented 6 years ago

Please follow the guide below


Before submitting an issue, make sure you have:

Purpose of your issue?

For a bug report, you must include the Python version used, code that will reproduce the error, and the error log/traceback.

Paste the output of python -V here:

Python 3.6.5

Code:

Any request, mostly when liking.

Error/Debug Log:

<Response [400]>
{'feedback_action': 'report_problem',
 'feedback_appeal_label': 'Report problem',
 'feedback_ignore_label': 'OK',
 'feedback_message': 'This action was blocked. Please try again later. We '
                     'restrict certain content and actions to protect our '
                     'community. Tell us if you think we made a mistake.',
 'feedback_title': 'Action Blocked',
 'feedback_url': 'repute/report_problem/instagram_like_add/',
 'message': 'feedback_required',
 'spam': True,
 'status': 'fail'}

Describe your issue

After a few months using this project (mostly the API section) I went through multiple issues, from login challenges to spam detections, IP bans, timeouts... I was able to solve most of them thanks to the documentation, issues here and googleing a bit.

My last issue has been being banned from liking from 5 of my 11 accounts I have in my bot. I have to say that I'm not using exactly this bot, but a custom made version, but is 100% based on this code and is also using the original instabot.api package, with just a couple of changes to make it Django compatible.

After 2 days debuging and trying with new proxies, servers, configurations and so on, I think I found a key part that was making the bot being detected as spam... I can see in instabot.api.config.py that the DEVICE_SETTINGS info is quite outdated, using old instagram api, android and release version. Also when making requests with API.send_request(), the current headers are

self.session.headers.update({
            'Connection': 'close',
            'Accept': '*/*',
            'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Cookie2': '$Version=1',
            'Accept-Language': 'en-US',
            'User-Agent': config.USER_AGENT
}

which are also not 100% complete.

Reading about the project, sources and more issues, I can see that two projects are named as sources:

Both of them have been updated recently with new configurations and versions for the user agent and headers. I think it would be nice to:

I suggest to have something like this on the config.py

DEVICES = {
    'Samsung Galaxy S7': {
        'name': 'Samsung Galaxy S7',
        'instagram_version': '26.0.0.10.86',
        'android_version': 24,
        'android_release': '7.0',
        'manufacturer': 'samsung',
        'device': 'SM-G930F',
        'model': 'herolte',
        'cpu': 'samsungexynos8890',
    },
    'Huawei Mate 9 Pro': {
        'name': 'Huawei Mate 9 Pro',
        'instagram_version': '26.0.0.10.86',
        'android_version': 24,
        'android_release': '7.0',
        'manufacturer': 'HUAWEI',
        'device': 'LON-L29',
        'model': 'HWLON',
        'cpu': 'hi3660'
    }
}
DEVICE_SETTINGS = DEVICES['Samsung Galaxy S7']
USER_AGENT = 'Instagram {instagram_version} Android ({android_version}/{android_release}; 640dpi; 1440x2560; {manufacturer}; {device}; {model}; {cpu}; en_US)'.format(**DEVICE_SETTINGS)

# --- Requests variables
ACCEPT_LANGUAGE = 'en-US'
ACCEPT_ENCODING = 'gzip,deflate'
CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=UTF-8'
X_FB_HTTP_Engine = 'Liger'
X_IG_Connection_Type = 'WIFI'
X_IG_Capabilities = '3brTBw=='  # = base64.b64encode(struct.pack('<i', 131316445)).decode('ascii')
IG_SIG_KEY = '99e16edcca71d7c1f3fd74d447f6281bd5253a623000a55ed0b60014467a53b1'

And update the API.send_request() with:

self.session.headers.update({
            'Connection': 'Keep-Alive',
            'X-IG-Capabilities': config.X_IG_Capabilities,
            'X-IG-Connection-Type': config.X_IG_Connection_Type,
            'X-FB-HTTP-Engine': config.X_FB_HTTP_Engine,
            'Accept': '*/*',
            'Accept-Encoding': config.ACCEPT_ENCODING,
            'Accept-Language': config.ACCEPT_LANGUAGE,
            'Content-type': config.CONTENT_TYPE,
            'Cookie2': '$Version=1',
            'User-Agent': config.USER_AGENT
})

This way it will be easier and more flexible to update devices when we found new ones, and also easier to update the requests headers, so we can be up to date and avoid being banned easely.

In summary: These are the changes I made on the project to be able to have all my accounts online and working again:

basnijholt commented 6 years ago

This sounds great! Would you like to make a Pull request?

JoeFertig commented 6 years ago

Sounds nice. Can you update the FULL code and paste it into your repository? Thank you :)

alberdonpi commented 6 years ago

Sure! I’ve been out these days, but I’ll prepare it and upload it next week!

JoeFertig commented 6 years ago

Thanks that would be awesome!

alberdonpi notifications@github.com schrieb am Sa. 9. Juni 2018 um 08:01:

Sure! I’ve been out these days, but I’ll prepare it and upload it next week!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/instagrambot/instabot/issues/562#issuecomment-395942958, or mute the thread https://github.com/notifications/unsubscribe-auth/Ajqylo-PmV7ohZnEGfNoTpn6jmBEsNKpks5t62TBgaJpZM4UYI5W .

Naramsim commented 6 years ago

Any updates?

lubislutfi commented 6 years ago

Still waiting. :)

alberdonpi commented 6 years ago

Sorry guys, I’ll do it this week, I got a “checkpint_challenge” problem with one of the accounts and I was implementing the solution to use email and phone codes using the api so it works with proxies also. I’ll upload all the code together.

lubislutfi commented 6 years ago

Sounds nice. I hope you can insert more device settings and update with "get random device" too, so it will choose the device automatically. thanks

@alberdonpi Sorry guys, I’ll do it this week, I got a “checkpint_challenge” problem with one of the accounts and I was implementing the solution to use email and phone codes using the api so it works with proxies also. I’ll upload all the code together.

basnijholt commented 6 years ago

... and update with "get random device" too, so it will choose the device automatically

I don't think this automatic switching of devices makes sense. Don't you think that Instagram would find that even more suspicious when you switch between devices all the time?

alberdonpi commented 6 years ago

Just did the pull request, is the first time I'm doing one so please tell me if I need to make any changes on it! I will finish the code to fix the "checkpoint_challenge" and test it on my app before creating another merge request.