ping / instagram_private_api

A Python library to access Instagram's private API.
MIT License
2.94k stars 608 forks source link

top_search not working #408

Open elisamercanti opened 1 year ago

elisamercanti commented 1 year ago

Please follow the guide below


Before submitting an issue, make sure you have:

Which client are you using?


Describe the Bug/Error:

I'm trying to have a preview of top matching hashtags, users, locations of a certain word and I'm using the dedicated function "top_search". The function gets called properly but a ClientError arises. I've already checked that email and password are good because they work just fine with other functions like feed_tag. The code and the error message are pasted below.


Code:

# Example code that will produce the error reported
from instagram_private_api import Client

email, password = MYEMAIL, MYPSW
api = Client(email, password)
resp = api.top_search('farfa')
resp

Error/Debug Log:

Error parsing error response: Expecting value: line 1 column 1 (char 0)
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/instagram_private_api/client.py in _call_api(self, endpoint, params, query, return_response, unsigned, version)
    522             self.logger.debug('DATA: {0!s}'.format(data))
--> 523             response = self.opener.open(req, timeout=self.timeout)
    524         except compat_urllib_error.HTTPError as e:

/usr/lib/python3.8/urllib/request.py in open(self, fullurl, data, timeout)
    530             meth = getattr(processor, meth_name)
--> 531             response = meth(req, response)
    532 

/usr/lib/python3.8/urllib/request.py in http_response(self, request, response)
    639         if not (200 <= code < 300):
--> 640             response = self.parent.error(
    641                 'http', request, response, code, msg, hdrs)

/usr/lib/python3.8/urllib/request.py in error(self, proto, *args)
    568             args = (dict, 'default', 'http_error_default') + orig_args
--> 569             return self._call_chain(*args)
    570 

/usr/lib/python3.8/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    501             func = getattr(handler, meth_name)
--> 502             result = func(*args)
    503             if result is not None:

/usr/lib/python3.8/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    648     def http_error_default(self, req, fp, code, msg, hdrs):
--> 649         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    650 

HTTPError: HTTP Error 404: Not Found

During handling of the above exception, another exception occurred:

ClientError                               Traceback (most recent call last)
<ipython-input-8-6fd8388a332f> in <module>
      1 wordQuery = 'farfa'
      2 
----> 3 resp = api.top_search(wordQuery)
      4 resp

/usr/local/lib/python3.8/dist-packages/instagram_private_api/endpoints/misc.py in top_search(self, query)
    136         :return:
    137         """
--> 138         res = self._call_api(
    139             'fbsearch/topsearch/',
    140             query={'context': 'blended', 'ranked_token': self.rank_token, 'query': query})

/usr/local/lib/python3.8/dist-packages/instagram_private_api/client.py in _call_api(self, endpoint, params, query, return_response, unsigned, version)
    525             error_response = self._read_response(e)
    526             self.logger.debug('RESPONSE: {0:d} {1!s}'.format(e.code, error_response))
--> 527             ErrorHandler.process(e, error_response)
    528 
    529         except (SSLError, timeout, SocketError,

/usr/local/lib/python3.8/dist-packages/instagram_private_api/errors.py in process(http_error, error_response)
    133             logger.warning('Error parsing error response: {}'.format(str(ve)))
    134 
--> 135         raise ClientError(error_msg, http_error.code, error_response)

ClientError: Not Found