CORS Issue with API running on Web2Py -


i've searching lot , although found similar issues, seems haven't found answer yet , maybe can me.

i have following api on web2py framework , accessing angularjs front-end app , having cors issues (i tried * in orign or specific ip , port no results). nevertheless, work ie not chrome or mozilla.

@request.restful() def api():     def get():         key = main() #generate random xml , returns key         response.headers['content-type'] = '*'         response.headers['access-control-allow-origin'] = '*'         response.headers['access-control-max-age'] = 86400         response.headers['access-control-allow-headers'] = '*'         response.headers['access-control-allow-methods'] = '*'         response.headers['access-control-allow-credentials'] = 'true'         response.view = 'generic.xml'         value = cb.get(key).value #get value stored couchbase         return value     return dict(get=get) 

more details error front-end app:

xmlhttprequest cannot load http://my_ip:8000/my_app/default/api/. response preflight request doesn't pass access control check: no 'access-control-allow-origin' header present on requested resource. origin 'http://my_ip:8080' therefore not allowed access. response had http status code 405.

from front-end app sure have right function calling api.

thanks!

your response headers need go outside of get() function.

@request.restful() def api():     response.view = 'generic.json'     response.headers["access-control-allow-origin"] = '*'     response.headers['access-control-max-age'] = 86400     response.headers['access-control-allow-headers'] = '*'     response.headers['access-control-allow-methods'] = '*'     response.headers['access-control-allow-credentials'] = 'true'      def get(tablename, id):         if not tablename == 'person':             raise http(400)         return dict(person = db.person(id))      def post(tablename, **fields):         if not tablename == 'person':             raise http(400)         return db.person.validate_and_insert(**fields)      return locals() 

http://web2py.com/books/default/chapter/29/10/services?search=restful#low-level-api-and-other-recipes


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -