Nov-05-2019, 09:14 AM
@snippsat
I used the code you sent me and it worked, but as soon as I changed the hashtag or datetime, it stopped working. Let's say I want all posts between 1 Jan. 2007 and 31. Dec. 2017 with the hashtag "bookerprize":
I used the code you sent me and it worked, but as soon as I changed the hashtag or datetime, it stopped working. Let's say I want all posts between 1 Jan. 2007 and 31. Dec. 2017 with the hashtag "bookerprize":
from datetime import datetime from itertools import dropwhile, takewhile import instaloader L = instaloader.Instaloader() posts = L.get_hashtag_posts('bookerprize') # or # posts = instaloader.Profile.from_username(L.context, PROFILE).get_posts() SINCE = datetime(2007, 1, 1) UNTIL = datetime(2017, 12, 31) for post in takewhile(lambda p: p.date > UNTIL, dropwhile(lambda p: p.date > SINCE, posts)): print(post.date) L.download_post(post, '#bookerprize')but it doesn't do anything. It takes an eternity for the "In [*]:" to change to "In [2]:" and when it does I get the following error:
Error:JSON Query to explore/tags/bookerprize/: 429 Too Many Requests [retrying; skip with ^C]
JSON Query to explore/tags/bookerprize/: 429 Too Many Requests [retrying; skip with ^C]
JSON Query to explore/tags/bookerprize/: HTTP error code 502. [retrying; skip with ^C]
---------------------------------------------------------------------------
TooManyRequestsException Traceback (most recent call last)
~\Anaconda\lib\site-packages\instaloader\instaloadercontext.py in get_json(self, path, params, host, session, _attempt)
373 if resp.status_code == 429:
--> 374 raise TooManyRequestsException("429 Too Many Requests")
375 if resp.status_code != 200:
TooManyRequestsException: 429 Too Many Requests
During handling of the above exception, another exception occurred:
TooManyRequestsException Traceback (most recent call last)
~\Anaconda\lib\site-packages\instaloader\instaloadercontext.py in get_json(self, path, params, host, session, _attempt)
373 if resp.status_code == 429:
--> 374 raise TooManyRequestsException("429 Too Many Requests")
375 if resp.status_code != 200:
TooManyRequestsException: 429 Too Many Requests
During handling of the above exception, another exception occurred:
TooManyRequestsException Traceback (most recent call last)
~\Anaconda\lib\site-packages\instaloader\instaloadercontext.py in get_json(self, path, params, host, session, _attempt)
373 if resp.status_code == 429:
--> 374 raise TooManyRequestsException("429 Too Many Requests")
375 if resp.status_code != 200:
TooManyRequestsException: 429 Too Many Requests
The above exception was the direct cause of the following exception:
ConnectionException Traceback (most recent call last)
<ipython-input-11-afa213953ceb> in <module>
13 UNTIL = datetime(2008, 12, 31)
14
---> 15 for post in takewhile(lambda p: p.date > UNTIL, dropwhile(lambda p: p.date > SINCE, posts)):
16 print(post.date)
17 L.download_post(post, '#bookerprize')
~\Anaconda\lib\site-packages\instaloader\instaloader.py in get_hashtag_posts(self, hashtag)
831 params = {'__a': 1}
832 hashtag_data = self.context.get_json('explore/tags/{0}/'.format(hashtag),
--> 833 params)['graphql']['hashtag']['edge_hashtag_to_media']
834 yield from (Post(self.context, edge['node']) for edge in hashtag_data['edges'])
835 has_next_page = hashtag_data['page_info']['has_next_page']
~\Anaconda\lib\site-packages\instaloader\instaloadercontext.py in get_json(self, path, params, host, session, _attempt)
411 if is_iphone_query and isinstance(err, TooManyRequestsException):
412 self._ratecontrol_graphql_query('iphone', untracked_queries=True)
--> 413 return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1)
414 except KeyboardInterrupt:
415 self.error("[skipped by user]", repeat_at_end=False)
~\Anaconda\lib\site-packages\instaloader\instaloadercontext.py in get_json(self, path, params, host, session, _attempt)
411 if is_iphone_query and isinstance(err, TooManyRequestsException):
412 self._ratecontrol_graphql_query('iphone', untracked_queries=True)
--> 413 return self.get_json(path=path, params=params, host=host, session=sess, _attempt=_attempt + 1)
414 except KeyboardInterrupt:
415 self.error("[skipped by user]", repeat_at_end=False)
~\Anaconda\lib\site-packages\instaloader\instaloadercontext.py in get_json(self, path, params, host, session, _attempt)
404 error_string = "JSON Query to {}: {}".format(path, err)
405 if _attempt == self.max_connection_attempts:
--> 406 raise ConnectionException(error_string) from err
407 self.error(error_string + " [retrying; skip with ^C]", repeat_at_end=False)
408 try:
ConnectionException: JSON Query to explore/tags/bookerprize/: 429 Too Many Requests
and I get no actual output. I have never had this problem with the command line version, but to be sure I used a different hashtag of which I know there are a lot less posts, but either I got the same error message, or I simply didn't get anything at all - no output, no error message. I tried to read their "troubleshooting" essay, but I don't understand it - I think my English may not be good enough when it comes to the specific terminology used. Would you please help and explain it to me? How can I solve this problem?