Skip to content

Commit

Permalink
data is to be passed to _request as 'params' always, pick POST or GET…
Browse files Browse the repository at this point in the history
… and convert from 'params' to 'data' as required in the _request function
  • Loading branch information
ramSeraph committed Jan 12, 2024
1 parent 66c654f commit 24764da
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions esridump/dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ def __init__(self, url, parent_logger=None,
self._logger = logging.getLogger('esridump')

def _request(self, method, url, **kwargs):

if method == 'POST' and self._use_only_get:
method = 'GET'

if method == 'POST':
if 'params' in kwargs:
kwargs['data'] = kwargs['params']
del kwargs['params']

if self._proxy:
url = self._proxy + url
params = kwargs.pop('params', None)
if params:
url += '?' + urlencode(params)
return self._requester(method, url, self._logger, self._http_timeout, **kwargs)

def _build_url(self, url=None):
Expand Down Expand Up @@ -143,9 +147,8 @@ def can_handle_pagination(self, query_fields):
})
headers = self._build_headers()
query_url = self._build_url('/query')
verb = 'GET' if self._use_only_get else 'POST'
response = self._request(
verb, query_url, headers=headers, data=check_args)
'POST', query_url, headers=headers, params=check_args)

try:
data = response.json()
Expand Down Expand Up @@ -369,8 +372,7 @@ def _is_oid_field_returned(self, oid, oid_field_name, query_fields):
})
headers = self._build_headers()
url = self._build_url('/query')
verb = 'GET' if self._use_only_get else 'POST'
response = self._request(verb, url, data=query_args, headers=headers)
response = self._request('POST', url, params=query_args, headers=headers)
data = self._handle_esri_errors(response, f"unable to retrieve feature with {oid}")
if data is None or data.get('features') is None or len(data.get('features')) != 1:
raise EsriDownloadError('Unable to query for oid field')
Expand Down Expand Up @@ -517,9 +519,6 @@ def run_query(self, query_url, headers, query_args, verb='POST'):
download_exception = None
data = None

request_arg_key = 'data' if verb == 'POST' else 'params'
request_args = { request_arg_key: query_args }

# try to do a request "num_of_retry" to increase the probability of fetching data successfully
for retry in range(self._num_of_retry):
try:
Expand All @@ -528,7 +527,7 @@ def run_query(self, query_url, headers, query_args, verb='POST'):
time.sleep(self._pause_seconds)
self._logger.info(
"pause for %s seconds", self._pause_seconds)
response = self._request(verb, query_url, headers=headers, **request_args)
response = self._request(verb, query_url, headers=headers, data=query_args)
data = self._handle_esri_errors(
response, "Could not retrieve this chunk of objects")
# reset the exception state.
Expand Down

0 comments on commit 24764da

Please sign in to comment.