Coder Social home page Coder Social logo

CORS? about flask-jsonrpc HOT 9 CLOSED

cenobites avatar cenobites commented on May 27, 2024
CORS?

from flask-jsonrpc.

Comments (9)

nycholas avatar nycholas commented on May 27, 2024

Hello,

Maybe it's the order the decorator, try:

@jsonrpc.method('addSession')
@crossdomain(origin='*', methods=['GET', 'OPTIONS', 'POST'])
def addSession(params):
      ...

Thank you.

from flask-jsonrpc.

byaka avatar byaka commented on May 27, 2024

When i'm change order, i have error when try to connect via python console and jsonrpclib (as serverProxy).

AppError                                  Traceback (most recent call last)
<ipython-input-57-e2ed3d81507c> in <module>()
----> 1 jsonrpclib.Server('http://0.0.0.0:8099/statsApi').random()

/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.pyc in __call__(self, *args, **kwargs)
    559             return self.__send(self.__name, args)
    560         else:
--> 561             return self.__send(self.__name, kwargs)
    562 
    563     def __getattr__(self, name):

/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.pyc in _request(self, methodname, params, rpcid)
    437                         config=self._config)
    438         response = self._run_request(request)
--> 439         check_for_errors(response)
    440         return response['result']
    441 

/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.pyc in check_for_errors(result)
   1117                 # Application error
   1118                 data = result['error'].get('data', None)
-> 1119                 raise AppError((code, message, data))
   1120 
   1121         elif isinstance(result['error'], dict) and len(result['error']) == 1:

AppError: (200, u'OtherError: 200 OK', None)

and in browser i also don't have "Access-Control-Allow-Origin header" in response.

from flask-jsonrpc.

byaka avatar byaka commented on May 27, 2024

with flask_jsonrpc.proxy.ServiceProxy i have error also

{u'error': {u'code': 200,
  u'data': None,
  u'message': u'OtherError: 200 OK',
  u'name': u'OtherError'},
 u'id': u'f42a81d2-aee3-11e4-8295-08606ee7f025',
 u'jsonrpc': u'2.0'}

from flask-jsonrpc.

byaka avatar byaka commented on May 27, 2024

i'm understand that problem in

make_response(f(*args, **kwargs))

from http://flask.pocoo.org/snippets/56/ decorator. This return a new response, but flask-jsonrpc wait not response, only result of function.
Problem how to transfer headers from another decorator to flask-jsonrpc, if flask-jsonrpc doesn't wait a response object...

from flask-jsonrpc.

nycholas avatar nycholas commented on May 27, 2024

I understand, would have to add the decorators list to be processed by the JSONRPC.

A while ago there was a pull request[#21] to accomplish this task. At the time, I thought was very intrusive, but now need to think better.

Thank you.

from flask-jsonrpc.

byaka avatar byaka commented on May 27, 2024

Thx for response, i will waiting

from flask-jsonrpc.

mfya avatar mfya commented on May 27, 2024

Instead of using the decorator from the snippet, you can try the Flask-CORS extension. At least it worked for me to have the header automatically added to all routes.

from flask-jsonrpc.

nycholas avatar nycholas commented on May 27, 2024

@byaka

It added support to designers that alter the response.

Look at the example decorator[1] for more details.

Note: To use this feature has added a helpers make_response (from flask_jsonrpc make_response import).

Fixed in version 0.3.

[1] - https://github.com/cenobites/flask-jsonrpc/blob/v0.3/examples/decorator/decorator.py#L70

Thank you.

from flask-jsonrpc.

byaka avatar byaka commented on May 27, 2024

Nice work!

from flask-jsonrpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.