Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traceback (most recent call last) - Random error occuring suddenly, while the bot is running fine. #4

Open
5 of 18 tasks
marcularis04 opened this issue Aug 14, 2019 · 14 comments

Comments

@marcularis04
Copy link

marcularis04 commented Aug 14, 2019

Check this or we will delete your issue. (fill in the checkbox with an X like so: [x])

  • I have searched for other issues with the same problem or similar feature requests.

Select one:

  • Bug
  • Feature Request
  • Technical Help (Please don't create an issue, join the facebook group or telegram channel)
  • Other

Environment

  • Are you hosting the bot on a VPS or other Cloud hosting?
  • Are you running the code on your phone
  • If so, have you tried running the code on your local machine?
Raspberry Pi - Raspbian

Operating System? (include version)

  • macOS
  • Windows
  • Rasbian Linux Raspberry PI (include flavour)
  • Linux (include flavour)
  • Android (include terminal)
Linux raspberrypi 4.19.57-v7+ #1244 SMP Thu Jul 4 18:45:25 BST 2019 armv7l GNU/Linux

Python Version Requirement

  • I am using Python 3.6 or above

Exact Python Version?

Python 3.7.3

Pip Version?

pip 18.1 from /home/pi/venv/lib/python3.7/site-packages/pip (python 3.7)

Instabot Version?

Installed version 0.5.9

How you use the instabot

  • instabot-py -c my-configfile.yml (my-configfile.yml is an example you may have a different file )
  • instabot-py --login LOGIN --password PASSWORD
  • instabot-py
  • example.py (Deprecated, please install newer version)

Description of your issue

I get this error randomly, while the bot is running:

Traceback (most recent call last):                           
 File "/ home/pi/venv/bin/instabot-py", line 10, in <module> sys.exit(main())  File "/home/pi/venv/lib/python3.7/site-packages/ instabot_py/__main__.py", line 304, in main    bot.mainloop()  File "/home/pi/venv/lib/python3.7/site-packages/ instabot_py/instabot.py", line 762, in mainloop    self.new_auto_mod_comments(media)  File "/home/pi/venv/lib/python3.7/sitepackages/instabot_py/instabot.py", line 1030, in new_auto_mod_comments    if self.iteration_ready("comments") and self.verify_media_before_comment(media):  File "/home/pi/venv/lib/python3.7/sitepackages/instabot_py/instabot.py", line 1082, in verify_media_before_comment    all_data = json.loads(raw_data)["entry_data"] ["PostPage"][0]  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads    return _default_decoder.decode(s)  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode    obj, end = self.raw_decode(s, idx=_w(s, 0).end())  File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode    obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 2590 (char 2589)

  File "/home/pi/venv/lib/python3.7/site-packages/instabot_py/__main__.py", line 304, in main
    bot.mainloop()
  File "/home/pi/venv/lib/python3.7/site-packages/instabot_py/instabot.py", line 762, in mainloop
    self.new_auto_mod_comments(media)
  File "/home/pi/venv/lib/python3.7/site-packages/instabot_py/instabot.py", line 1030, in new_auto_mod_comments
    if self.iteration_ready("comments") and self.verify_media_before_comment(media):
  File "/home/pi/venv/lib/python3.7/site-packages/instabot_py/instabot.py", line 1082, in verify_media_before_comment
    all_data = json.loads(raw_data)["entry_data"]["PostPage"][0]
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 2563 (char 2562)

It's the same format always, just the line numbers differ. It just appears randomy, while the bot is running REALLY well. Then, Instabot stops working. After the error, I can restart Instabot, run it for 3-4 hours, then when I return at the SSH terminal, it shows me this error. Sometimes, this error appears immediately after running. It's the same always, only the line numbers differ. I have installed the latest Instabot with this tutorial:

#Install python3-venv to create virtual env
# In Ubuntu, install it using apt
sudo apt install python3-venv 
# Create a virtual env 
python3 -m venv venv 
source venv/bin/activate
pip install instabot-py
instabot-py --version

The source is https://medium.com/@asker_amine/whats-new-in-the-instagram-bot-0-5-2-fe52154fdc8a

#### Config
login : "myusername"
password : "mypassword"
accept_language: en-US,en;q=0.5
ban_sleep_time: 10800
comment_list:
- (my comments)
comments_per_day: 24
comments_per_run: '{{comments_per_day}}'
database:
  connection_string: sqlite:///{{database.path}}
  path: '{{login}}.db'
  type: sql
debug: 0
dump_configuration: false
end_at_h: 21
end_at_m: 45
error_400_to_ban: 3
follow_per_day: 30
follow_per_run: 30
follow_time: 18000
follow_time_enabled: true
like_per_day: 30
like_per_run: 30
list_of_ua:
- Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; FSL 7.0.6.01001)
- Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; FSL 7.0.7.01001)
- Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; FSL 7.0.5.01003)
- Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
- Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid)
  Firefox/3.6.8
- Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1
- Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0
- Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid)
  Firefox/3.6.8
- Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)
- Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
- Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727;
  .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
- Opera/9.80 (Windows NT 5.1; U; en) Presto/2.10.289 Version/12.01
- Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
- Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1
- Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.02
- Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112
  Safari/535.1
- Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.0) Opera 7.02 Bork-edition
  [en]
log_mod: 0
logging:
  disable_existing_loggers: false
  formatters:
    simple:
      format: '%(asctime)s - {{login}} - %(name)s - %(levelname)s - %(message)s'
  handlers:
    console:
      class: logging.StreamHandler
      formatter: simple
      level: DEBUG
      stream: ext://sys.stdout
  loggers:
    InstaBot:
      handlers:
      - console
      level: DEBUG
      propagate: 'no'
    Persistence:
      handlers:
      - console
      level: DEBUG
      propagate: 'no'
  root:
    level: INFO
  version: 1
max_like_for_one_tag: 11
media_max_like: 150
media_min_like: 0
session_file: '{{login}}.session'
start_at_h: 9
start_at_m: 30
tag_list:
- (my list)
time_till_unlike: 0
unfollow_break_max: 75
unfollow_break_min: 50
unfollow_everyone: false
unfollow_inactive: true
unfollow_not_following: true
unfollow_per_day: 30
unfollow_per_run: 30
unfollow_probably_fake: true
unfollow_recent_feed: false
unfollow_selebgram: false
unlike_per_day: 0
unlike_per_run: 0
user_max_follow: 0
user_min_follow: 0
window_check_every: 300
@iamklaus
Copy link

Same for me

@yurilaaziz
Copy link
Owner

Thank you for your interest
Instagram sometimes returns non expected result.
I will try to reproduce the error and fix it

@marcularis04
Copy link
Author

Thank you very much!! This error literally destroys an excellent working bot, making it unusable. My question is, why it's an isolated case, when the problem is at Insgagram's part?

@marcularis04
Copy link
Author

Thanks to everybody! Yesterday, right after my last answer I tried uninstalling instabot-py, and reinstalling it with python3 -m pip install instabot-py, instead of pip install instabot-py, like the Medium's article tutorial suggests. Now, it has been working like a charm all day :)

@marcularis04
Copy link
Author

Edit: No, it was just good luck. It worked for 23-24 hours, then this error happened again. I don't know what to do.. . :( @yurilaaziz please try fixing this error, it's so frustrating.. :(

@marcularis04
Copy link
Author

Have you found a solution? Should I try running it outside the venv?

@marcularis04
Copy link
Author

Running it outside Venv doesn't help either. I've also updated python3 to version 3.7.4, it just doesn't help. Anyone else is facing this error? I literary can't run the bot all day, because at some point in time it just stops working.

@iamklaus
Copy link

iamklaus commented Aug 20, 2019

Running it outside Venv doesn't help either. I've also updated python3 to version 3.7.4, it just doesn't help. Anyone else is facing this error? I literary can't run the bot all day, because at some point in time it just stops working.

Instead of running the bot directly, run this script instead. Whenever the bot crashes, the script starts a new process:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import time
import signal
import sys

def signal_handler(sig, frame):
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

myCmd = '/usr/local/bin/instabot-py -c _iamklaus.yml'

while True:
    try:
        os.system(myCmd)
    except:
        continue
    print ("#################################################")
    print ("Going to sleep for 10 seconds.")
    print ("#################################################")
    time.sleep(10)

@marcularis04
Copy link
Author

Thanks! Right now I am experimenting with Instapy, because this project is officially shut down for an undetermined period of time, and also because it's easy for Instagram to detect it, even on 40 likes per day.

@artgolwebdev
Copy link

Do you use proxy ?
It seems to me to work with proxy!!! I got the same error before I used proxyyy.. But the question is how long will proxy help.

@marcularis04
Copy link
Author

No, I don't use a proxy. What is a proxy for? Does it prevent instagram from detecting the bot?

@artgolwebdev
Copy link

artgolwebdev commented Aug 27, 2019

No, I don't use a proxy. What is a proxy for? Does it prevent instagram from detecting the bot?

◘ A proxy server acts as a gateway between you and the internet. ... Modern proxy servers do much more than forwarding web requests, all in the name of data security and network performance.

◘ it will not prevent but suppose to help.

@artgolwebdev
Copy link

Thank you for your interest
Instagram sometimes returns non expected result.
I will try to reproduce the error and fix it

Hi! I was getting the same error in verify_media_before_comment function
After digging into code I figured out it could not retrieve json data.
So I added simple try and catch and now bot continues to run.
Maby we can use it as "patch" untill now
bot.py line 1060
try: all_data = json.loads(raw_data)["entry_data"]["PostPage"][0] except Exception as exc: self.logger.warning("Cannot retrieve comments from media.(all_data) ") self.logger.exception(exc) return False

MY LOG

2019-08-27 16:34:06,496 - artyom.js - InstaBot - INFO - Saving cookies to session file artyom.js.session
2019-08-27 16:34:06,501 - artyom.js - InstaBot - INFO - Reading configuration (3 settings) from artconfig.yml
2019-08-27 16:34:06,501 - artyom.js - InstaBot - DEBUG - Get Media by tag: bgirl
2019-08-27 16:34:08,404 - artyom.js - InstaBot - DEBUG - Retrieved 69 medias
2019-08-27 16:34:08,476 - artyom.js - InstaBot - DEBUG - Select 13 medias to process. Increase max_like_for_one_tag value for more processing medias
2019-08-27 16:34:08,477 - artyom.js - InstaBot - DEBUG - Trying to like media: id: 2119722654127401344, url: https://www.instagram.com/p/B1qxIXtnKmA/
2019-08-27 16:34:09,170 - artyom.js - InstaBot - INFO - Liked media #1: id: 2119722654127401344, url: https://www.instagram.com/p/B1qxIXtnKmA/
2019-08-27 16:34:10,809 - artyom.js - InstaBot - DEBUG - Trying to follow: thevandalhour
2019-08-27 16:34:11,665 - artyom.js - InstaBot - INFO - Followed: https://www.instagram.com/thevandalhour/ #1.
2019-08-27 16:34:12,135 - artyom.js - InstaBot - WARNING - Cannot retrieve comments from media.(all_data)
2019-08-27 16:34:12,136 - artyom.js - InstaBot - ERROR - Unterminated string starting at: line 1 column 2237 (char 2236)
Traceback (most recent call last):
File "c:\users\roey\appdata\local\programs\python\python37\lib\site-packages\instabot\bot.py", line 1062, in verify_media_before_comment
all_data = json.loads(raw_data)["entry_data"]["PostPage"][0]
File "c:\users\roey\appdata\local\programs\python\python37\lib\json_init_.py", line 348, in loads
return _default_decoder.decode(s)
File "c:\users\roey\appdata\local\programs\python\python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "c:\users\roey\appdata\local\programs\python\python37\lib\json\decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 2237 (char 2236)
2019-08-27 16:34:12,683 - artyom.js - InstaBot - INFO - Trying to comment: 2119724541454582423 https://www.instagram.com/p/B1qxj1bFAKX/
2019-08-27 16:34:15,007 - artyom.js - InstaBot - INFO - Comment: The picture feels very cool... #1.
2019-08-27 16:56:56,472 - artyom.js - InstaBot - DEBUG - Trying to follow: frente_mulheres_hiphop_ba
2019-08-27 16:56:57,521 - artyom.js - InstaBot - INFO - Followed: https://www.instagram.com/frente_mulheres_hiphop_ba/ #2.

@mbe9477
Copy link

mbe9477 commented Sep 7, 2019

Running it outside Venv doesn't help either. I've also updated python3 to version 3.7.4, it just doesn't help. Anyone else is facing this error? I literary can't run the bot all day, because at some point in time it just stops working.

Instead of running the bot directly, run this script instead. Whenever the bot crashes, the script starts a new process:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import time
import signal
import sys

def signal_handler(sig, frame):
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

myCmd = '/usr/local/bin/instabot-py -c _iamklaus.yml'

while True:
    try:
        os.system(myCmd)
    except:
        continue
    print ("#################################################")
    print ("Going to sleep for 10 seconds.")
    print ("#################################################")
    time.sleep(10)

Hi @iamklaus
I'd like to try this one. But I have no experiance with Scripts.
I am on MacOS Mojave. And have the Script Editor as tool.
Could you help me which of the above lines I have to adjust to my setting / storage location of the bot?
Thanks for your help.

Regards,
Marc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants