instagrapi
instagrapi copied to clipboard
[BUG] How to avoid unusual activity on instagram with/without proxy
Describe the bug Is there a way to avoid 'unusual activity' by instagram? Doesn't make any difference if I use proxy. Instagram always detect new device on US and send mea verification code. After entering the code it says my location is United States which is clearly not truth. If I use proxy, paid high quality I receive same location warning on my mail by instagram.
To Reproduce
import json
import logging
import time
import requests
from instagrapi import Client
logging.basicConfig(level=logging.INFO)
# Question about using a proxy
while True:
use_proxy = input("Do you want to use a proxy? (yes/no): ").strip().lower()
if use_proxy in ("yes", "no"):
break
else:
print("Please answer 'yes' or 'no'.")
# Question about proxy details (if 'yes' is selected)
proxy_details = None
if use_proxy == "yes":
while True:
proxy_details = input("Please provide proxy details (ip:port:username:password): ").strip()
if proxy_details and len(proxy_details.split(':')) == 4:
break
else:
print("Please provide valid proxy details in the format ip:port:username:password.")
else:
proxy_details = 'no_proxy'
# Configure the client
cl = Client()
# Set up the proxy (if provided)
if proxy_details != 'no_proxy':
ip, port, username, password = proxy_details.split(':')
proxy_url = f'http://{username}:{password}@{ip}:{port}'
cl.set_proxy(proxy_url)
# Test the proxy
try:
before_ip = requests.get("https://api.ipify.org/", proxies={"http": proxy_url}).text
print(f"HTTP status before setting up the proxy: {before_ip}")
cl.set_proxy(proxy_url)
after_ip = cl._send_public_request("https://api.ipify.org/")
print(f"HTTP status after setting up the proxy: {after_ip}")
except Exception as e:
logging.error(f"Error while testing the proxy: {e}")
exit(1)
# Log in to Instagram
username = input("Please enter your username: ")
password = input("Please enter your password: ")
try:
cl.login(username, password)
time.sleep(2)
except Exception as e:
logging.error(f"Error during login: {e}")
exit(1)
filename = f'session_{username}.json'
try:
settings = cl.get_settings()
settings['proxy'] = proxy_details
with open(filename, 'w') as f:
json.dump(settings, f)
print(f"Session settings have been saved to the file {filename}")
except Exception as e:
logging.error(f"Error while saving session settings: {e}")
Expected behavior
Location tracked by instagram releated to proxy / local ip.
Desktop:
- OS: Microsoft Windows 11 Pro 10.0.22621
- Python version 3.11.3
- instagrapi version 2.0.2
- moveipy version if used: None
- imagemagick version if used: None
Would love to know if you successfully mitigate this
You may want to try the following:
- Verify your IG account with a phone number
- Create a json file with your custom settings client.dump_settings() and set a custom device info in the .json, not the default one.
- Before you login, always load those custom settings using client.load_settings() and client.set_settings(). For more info on how to use those methods: https://subzeroid.github.io/instagrapi/usage-guide/best-practices.html
- Assign one proxy to each account (maximum 5 per proxy IP, this number may have changed, its up to instagram).
- The proxy has to be a high-quality one (private residential, mobile proxy, etc.) that instagram doesn't recognize as a bot proxy.
Would love to know if you successfully mitigate this
Sorry for late response. I noticed instagram is bugged with these locations. Even if I use proxifier or similar tools I can't login to instagram with correct location, obviously other websites such as: nordvpn ip location etc. detect correct location. Instagram detects different.