diff --git a/fbchat/client.py b/fbchat/client.py index 934abd4..79adb39 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -96,13 +96,13 @@ class Client(object): self.req_counter += 1 return payload - def _fix_fb_errors(self, error): + def _fix_fb_errors(self, error_code): """ This fixes "Please try closing and re-opening your browser window" errors (1357004) This error usually happens after 1-2 days of inactivity It may be a bad idea to do this in an exception handler, if you have a better method, please suggest it! """ - if isinstanceof(error, FBchatFacebookError) and error.fb_error_code == '1357004': + if error_code == '1357004': log.warning('Got error #1357004. Doing a _postLogin, and resending request') self._postLogin() return True @@ -115,8 +115,8 @@ class Client(object): return r try: return check_request(r, as_json=as_json) - except FBchatException as e: - if error_retries > 0 and self._fix_fb_errors(e): + except FBchatFacebookError as e: + if error_retries > 0 and self._fix_fb_errors(e.fb_error_code): return self._get(url, query=query, timeout=timeout, fix_request=fix_request, as_json=as_json, error_retries=error_retries-1) raise e @@ -127,8 +127,8 @@ class Client(object): return r try: return check_request(r, as_json=as_json) - except FBchatException as e: - if error_retries > 0 and self._fix_fb_errors(e): + except FBchatFacebookError as e: + if error_retries > 0 and self._fix_fb_errors(e.fb_error_code): return self._post(url, query=query, timeout=timeout, fix_request=fix_request, as_json=as_json, error_retries=error_retries-1) raise e @@ -136,8 +136,8 @@ class Client(object): content = self._post(self.req_url.GRAPHQL, payload, fix_request=True, as_json=False) try: return graphql_response_to_json(content) - except FBchatException as e: - if error_retries > 0 and self._fix_fb_errors(e): + except FBchatFacebookError as e: + if error_retries > 0 and self._fix_fb_errors(e.fb_error_code): return self._graphql(payload, error_retries=error_retries-1) raise e diff --git a/fbchat/models.py b/fbchat/models.py index a1b2f35..a380599 100644 --- a/fbchat/models.py +++ b/fbchat/models.py @@ -21,15 +21,6 @@ class FBchatFacebookError(FBchatException): self.fb_error_message = fb_error_message self.request_status_code = request_status_code -class FBchatRedirectError(Exception): - #: The url that Facebook redirected to - fb_redirect_url = None - def __init__(self, message, fb_redirect_url=None): - super(FBchatException, self).__init__(message) - """Thrown by fbchat when Facebook returns an unexpected redirect""" - self.fb_redirect_url = str(fb_redirect_url) - - class FBchatUserError(FBchatException): """Thrown by fbchat when wrong values are entered""" diff --git a/fbchat/utils.py b/fbchat/utils.py index 8c8fc08..2b31228 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -187,10 +187,6 @@ def generateOfflineThreadingID(): return str(int(msgs, 2)) def check_json(j): - if not j.get('payload') and j.get('jsmods') is not None and j['jsmods'].get('require') is not None: - for x in j['jsmods']['require']: - if len(x) > 3 and x[0] == 'ServerRedirect' and x[1] == 'redirectPageTo': - return FBchatRedirectError('Redirect when sending request: {}'.format(j), fb_redirect_url=x[3][0]) if j.get('error') is None: return if 'errorDescription' in j: