WillReynolds5 / AutoGPT-Social

Autonomous Instagram bot which creates and optimizes posts to maximize engagement
MIT License
296 stars 51 forks source link

HTTP error code 401 when add hashtags ( initialize_bot.py ) #6

Open leonidussaks opened 1 year ago

leonidussaks commented 1 year ago

when i run initialize_bot.py and add hashtag this throw me error HTTP error code 401. I tried looking for this error on instaloader but culdn't fix it.

i tried it locally on my pc (with VPN) and VPS

I commented out the line on line 59 in initialize_bot.py hashtags = get_related_hashtags([hashtag.strip().replace('#', '') for hashtag in hashtags_input.split(',')]) and the bot post a picture with text, as it should be (i think).

error:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 352, in get_json
    raise ConnectionException("HTTP error code {}.".format(resp.status_code))
instaloader.exceptions.ConnectionException: HTTP error code 401.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/AutoGPT-Social/initialize_bot.py", line 66, in <module>
    main()
  File "/home/ubuntu/AutoGPT-Social/initialize_bot.py", line 59, in main
    hashtags = get_related_hashtags([hashtag.strip().replace('#', '') for hashtag in hashtags_input.split(',')])
  File "/home/ubuntu/AutoGPT-Social/instagram_util/hashtags.py", line 11, in get_related_hashtags
    posts = L.get_hashtag_posts(hashtag)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/instaloader/instaloader.py", line 1187, in get_hashtag_posts
    return Hashtag.from_name(self.context, hashtag).get_posts_resumable()
  File "/home/ubuntu/.local/lib/python3.10/site-packages/instaloader/structures.py", line 1539, in from_name
    hashtag._obtain_metadata()
  File "/home/ubuntu/.local/lib/python3.10/site-packages/instaloader/structures.py", line 1553, in _obtain_metadata
    self._node = self._query({"__a": 1, "__d": "dis"})
  File "/home/ubuntu/.local/lib/python3.10/site-packages/instaloader/structures.py", line 1548, in _query
    json_response = self._context.get_json("explore/tags/{0}/".format(self.name), params)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 395, in get_json
    return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 395, in get_json
    return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/instaloader/instaloadercontext.py", line 385, in get_json
    raise ConnectionException(error_string) from err
instaloader.exceptions.ConnectionException: JSON Query to explore/tags/it/: HTTP error code 401.
WillReynolds5 commented 1 year ago

quick fix. if you know which hashtags to use. replace that line with something like this hashtags = "hashtag1 hashtag2" do not include # in the hashtags

leonidussaks commented 1 year ago

Yes, I already did that, I just think the problem can happen not only for me. Thanks for reply anyway

techinAI commented 1 year ago

I tried, either with , or not within "" and it does not work.

sznegnsz commented 1 year ago

please fix this. I stuck at this level for days. that quick fix didn't work for me.