I'm running InstaPy on a macOS server in headless mode, and recently unfollowing stopped working with the following error message:
INFO [2018-11-05 09:32:48] [danniefraim] Ongoing Unfollow [1/5000]: now unfollowing 'username'...
WARNING [2018-11-05 09:33:54] [danniefraim] Phew! Last unfollow is not verified. ~'danniefraim' might be temporarily blocked from unfollowing
WARNING [2018-11-05 09:36:53] [danniefraim] There is a serious issue: 'temporary block'! ~leaving Unfollow-Users activity
INFO [2018-11-05 09:36:53] [danniefraim] --> Total people unfollowed : 0
I have checked, and I am not temporarily blocked, but the user is not unfollowed nonetheless. While testing I managed to figure out what triggers this behaviour. If I have a graphical session open on the server, i.e. I access it through screen sharing and log in my user, unfollowing works fine. But if I log out my graphical session, it stops working. This happens regardless of whether the headless_browser parameter is True or False (but I normally set it to True). And this happens even if I start the script using a separate ssh session to the server. The key is that I must have the GUI session open too, or it won't work. Liking and following works just fine regardless of the GUI session.
Here is the configuration I use for my unfollow script:
# coding=UTF-8
from instapy import InstaPy
insta_username = 'danniefraim'
insta_password = 'thisisnotmypassword'
try:
session = InstaPy(username=insta_username, password=insta_password, headless_browser=True)
session.login()
session.unfollow_users(amount=5000, InstapyFollowed=(True, "all"), style="FIFO", unfollow_after=48*60*60)
finally:
session.end()
This started happening some time in the last few weeks. I will look into what might be causing it when I have time, but if someone else has an idea what might be causing it or knows how to fix it, I'd like to know!
After looking at the history, I'm pretty sure this is related to the major changes by @uluQulu. Want to have a look?
How do you tell that you are not blocked ? it potentially blocked on the web, but not on the phone app. reduce the amount of activities. I see you set to unfollow 5000 users. it is a crazy amount compare to what I use/see. try to unfollow under 50 each run.
@CharlesCCC I can tell very easily that I am not blocked. First of all, I tried using the web browser on the computer running the script - not blocked. But even more, I can do this:
I can do the above ten times over, in a matter of minutes, and the same things happen. So in other words, I am 100% sure I am not blocked. Also, the number 5000 has absolutely nothing to do with the problem. This happens on the very first unfollow attempt, even if I have not interacted with Instagram for several days. I could set the script to unfollow 1 person, the problem would still appear.
If you don't believe me, I can send you a video showing you how I reproduce the issue. It is 100% reproducible and the only factor that seems to affect is whether I have a GUI session active on the server or not.
I am trying to troubleshoot this myself. Could you please keep the issue open at least until I give up?
@danniefraim Sure, I would suggest go with lower interaction amount regardless what the situation is. There are plenty similar situation happened in the past. Let us know if there is any additional insight you have found.
@CharlesCCC The above script is an example to reproduce the issue. Or, well, I set the unfollow amount to 5000 because I'm currently following 6000 people after I didn't notice that the unfollow function was broken! In my "normal" everyday script that the server is usually running 24/7 I call the unfollow function with 50 people at a time, in a loop that also contains a few calls to interact with hashtags. It's been working great for many months without ever getting blocked.
This particular issue is a bit tricky to troubleshoot, since I have to do it in headless mode on a server where I'm not logged in by other means than ssh... What I've found so far is that there is in fact a follow_button element, and that when element.click() is called inside click_element() there is no exception thrown. Yet, the button is clearly not clicked, and that's why the verification code is failing.
It is possible that this is actually a bug in Selenium or Chrome or has to do with permissions or rendering in macOS when running without a user graphically logged in, but since it has worked before and all the other functions like following are in fact working, it should be possible to fix in the InstaPy code. I'd run in a Docker container instead, but this server is actually too old to support Docker...
There is a limit how many user you can unfollow each hour/day that set by Instagram.com (not remember exactly amount but you might find through previous thread). So, a reasonable guess is you just reached that threshold. As run with GUI, you might found out, it not actually unfollowed the user (even the page might shows so), after a fresh, you will still see the "Following" button.
@danniefraim If you can, fire up the same configure on your local mac (or if is a container). and then to see if you can reproduce it locally. if reproducible, great, we can debug it locally. if not, then it might have something to do with the server you are using. it sounds like your are using a shared server ?(IDC?) it might not working as most of the shared server like Digital Ocean are blocked by Instagram.com already.
@CharlesCCC If I am to reproduce it on my local machine, I'd have to remote to my machine from another one since I'd have to be logged out for the bug to happen. But I suppose I could try that at the office. But it wouldn't really help in debugging, as I would still have to be logged out of the computer and couldn't run it in a graphical anyway. But I suppose I could try debugging it using pdb.
It's not really a shared server, at least not in the sense you mean. It's an old iMac we have at our two man office which is acting as a file server and general purpose task runner. It's not blocked, because the script is running just fine as long as I'm logged onto the graphical console of the computer.
I've been doing some more troubleshooting here. I've tried increasing the window size, in case the button was obscured or too small. I've tried specifying the Chrome user data directory. None of it worked. So I decided to try using Firefox instead, and discovered that Firefox is even more afflicted - Firefox actually won't start at all unless I'm graphically logged onto the computer.
So there just seems to be something very odd in how macOS handles apps like Chrome and Firefox when there's no active GUI session.
In the end, I decided to ditch macOS completely and instead deploy a virtual Linux server on AWS to run the bot. It only took me 15 minutes to have it up and running, after having spent hours and hours troubleshooting. So for me, this issue can be closed as unresolved.
@danniefraim Which AWS server is best/cheapest to run the bot? I'm running into the same issue as you, however on windows running headless. The error appears even after multiple days of inactivity then simply following one time with the bot.
@LotusPainter I signed up for Amazon EC2 and launched a t2.micro instance with the Amazon Linux 2 AMI. It's free for one year, then I think it's like $8 a month or something like that. Then I used the installation script on this page to install Chrome: https://intoli.com/blog/installing-google-chrome-on-centos/
After that, you just need to git pull, install virtualenv and pip, create a venv, and install the requirements with pip and you're ready to go.
@danniefraim could you fix this issue?