kandi X-RAY | cherrypy-cors Summary
kandi X-RAY | cherrypy-cors Summary
cherrypy-cors
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cherrypy-cors
cherrypy-cors Key Features
cherrypy-cors Examples and Code Snippets
Community Discussions
Trending Discussions on cherrypy-cors
QUESTION
When creating a post request from my website to my Python server running CherryPy, I receive the error Access to XMLHttpRequest has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
. I was able to get away with the problem temporarily with one of the "CORS Everywhere" browser extensions, but
- Due to recent updates, the extensions have not yet been updated to be working again.
- The website involved needs to eventually be used by many in my local complex without the browser extension, so once the extensions get updated, it does not really matter one way or another, as I cannot rely on these extensions, and force everyone to use them (when there is obviously a fix that would make an extension not necessary). I figure that perhaps the solutions are outdated, but am not sure.
Here is the relevant code:
On the server side (CherryPy/Python):The CherryPy Python function being called, from the website post request
...ANSWER
Answered 2019-Aug-26 at 07:25So first, you need to set pre-flight headers when processing OPTIONS
request, you can list allowed methods there.
Then, you also need to enable the cors.expose
tool.
There's some usage hints in the docstring of cherrypy-cors
. For example, when using a MethodDispatcher
, you could just decorate an OPTIONS
handler method with @cherrypy_cors.tools.preflight()
instead of doing this in every HTTP handler.
Here's a simple traversal example (without a method dispatcher). To test it, visit http://127.0.0.1/ and it will make requests against http://localhost:3333/add_meeting which is a different Origin
in terms of CORS ('localhost' != '127.0.0.1'
).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cherrypy-cors
No Installation instructions are available at this moment for cherrypy-cors.Refer to component home page for details.
Support
If you have any questions vist the community on GitHub, Stack Overflow.
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page