Skip to content
This repository
Browse code

fix bug in request HTTP XML (HRX)

  • Loading branch information...
commit 29f4cd7225e50fee621c220248269f4b41e87bc1 1 parent 624ae3a
Nycholas de Oliveira e Oliveira nycholas authored

Showing 2 changed files with 12 additions and 9 deletions. Show diff stats Hide diff stats

  1. +6 3 flask_jsonrpc/helpers.py
  2. +6 6 flask_jsonrpc/site.py
9 flask_jsonrpc/helpers.py
@@ -3,7 +3,7 @@
3 3 # All rights reserved.
4 4 from functools import wraps
5 5
6   -from flask import current_app, request, jsonify
  6 +from flask import current_app, request, jsonify, json
7 7
8 8 from flask_jsonrpc.exceptions import InvalidCredentialsError, InvalidParamsError
9 9
@@ -22,10 +22,13 @@ def extract_raw_data_request(request):
22 22 if request.method == 'GET':
23 23 return request.query_string
24 24 elif request.method == 'POST':
25   - if request.data:
  25 + # True if the request was triggered via a JavaScript
  26 + # XMLHttpRequest
  27 + if request.is_xhr:
  28 + return json.dumps(request.form.to_dict())
  29 + elif request.data:
26 30 return request.data
27 31 elif request.form.to_dict():
28   - #return '&'.join(['{}={}'.format(k,v) for k,v in request.form.to_dict().items()])
29 32 return request.form.to_dict().keys()[0]
30 33 return ''
31 34
12 flask_jsonrpc/site.py
@@ -140,7 +140,7 @@ def response_dict(self, request, D, is_batch=False, version_hint='1.0'):
140 140 '1.1': lambda f, r, p: f(*encode_arg11(p), **encode_kw(encode_kw11(p))),
141 141 '1.0': lambda f, r, p: f(*p)
142 142 }
143   -
  143 +
144 144 try:
145 145 # params: An Array or Object, that holds the actual parameter values
146 146 # for the invocation of the procedure. Can be omitted if empty.
@@ -189,7 +189,7 @@ def response_dict(self, request, D, is_batch=False, version_hint='1.0'):
189 189
190 190 except Error, e:
191 191 #got_request_exception.connect(log_exception, current_app._get_current_object())
192   -
  192 +
193 193 response['error'] = e.json_rpc_format
194 194 if version in ('1.1', '2.0') and 'result' in response:
195 195 response.pop('result')
@@ -197,7 +197,7 @@ def response_dict(self, request, D, is_batch=False, version_hint='1.0'):
197 197 except Exception, e:
198 198 # exception missed by others
199 199 #got_request_exception.connect(log_exception, current_app._get_current_object())
200   -
  200 +
201 201 other_error = OtherError(e)
202 202 response['error'] = other_error.json_rpc_format
203 203 status = other_error.status
@@ -218,7 +218,7 @@ def dispatch(self, request, method=''):
218 218 # json-rpc response
219 219 response = self.empty_response()
220 220 raw_data = extract_raw_data_request(request)
221   -
  221 +
222 222 try:
223 223 if request.method == 'GET':
224 224 valid, D = self.validate_get(request, method)
@@ -230,8 +230,8 @@ def dispatch(self, request, method=''):
230 230 else:
231 231 try:
232 232 D = json.loads(raw_data)
233   - except:
234   - raise InvalidRequestError
  233 + except Exception, e:
  234 + raise InvalidRequestError(e.message)
235 235
236 236 if type(D) is list:
237 237 response = [self.response_dict(request, d, is_batch=True)[0] for d in D]

0 comments on commit 29f4cd7

Please sign in to comment.
Something went wrong with that request. Please try again.