diff --git a/fbchat/_client.py b/fbchat/_client.py index 4aadc5f..b431aee 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -111,30 +111,8 @@ class Client(object): def _get(self, url, params): return self._state._get(url, params) - def _post(self, url, data, files=None, as_graphql=False, error_retries=3): - data.update(self._state.get_params()) - r = self._state._session.post(prefix_url(url), data=data, files=files) - content = check_request(r) - try: - if as_graphql: - return _graphql.response_to_json(content) - else: - j = to_json(content) - # TODO: Remove this, and move it to _payload_post instead - # We can't yet, since errors raised in here need to be caught below - handle_payload_error(j) - return j - except FBchatPleaseRefresh: - if error_retries > 0: - self._state._do_refresh() - return self._post( - url, - data, - files=files, - as_graphql=as_graphql, - error_retries=error_retries - 1, - ) - raise + def _post(self, url, params, files=None, as_graphql=False): + return self._state._post(url, params, files=files, as_graphql=as_graphql) def _payload_post(self, url, data, files=None): j = self._post(url, data, files=files) diff --git a/fbchat/_state.py b/fbchat/_state.py index aec72a1..56c7253 100644 --- a/fbchat/_state.py +++ b/fbchat/_state.py @@ -7,7 +7,7 @@ import re import requests import random -from . import _util, _exception +from . import _graphql, _util, _exception FB_DTSG_REGEX = re.compile(r'name="fb_dtsg" value="(.*?)"') @@ -215,3 +215,28 @@ class State(object): return self._get(url, params, error_retries=error_retries - 1) raise return j + + def _post(self, url, data, files=None, as_graphql=False, error_retries=3): + data.update(self.get_params()) + r = self._session.post(_util.prefix_url(url), data=data, files=files) + content = _util.check_request(r) + try: + if as_graphql: + return _graphql.response_to_json(content) + else: + j = _util.to_json(content) + # TODO: Remove this, and move it to _payload_post instead + # We can't yet, since errors raised in here need to be caught below + _util.handle_payload_error(j) + return j + except _exception.FBchatPleaseRefresh: + if error_retries > 0: + self._do_refresh() + return self._post( + url, + data, + files=files, + as_graphql=as_graphql, + error_retries=error_retries - 1, + ) + raise