Skip to content

Instantly share code, notes, and snippets.

@zacknawrocki
Created August 24, 2019 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zacknawrocki/8024f8f4566563c93362224bb97e702d to your computer and use it in GitHub Desktop.
Save zacknawrocki/8024f8f4566563c93362224bb97e702d to your computer and use it in GitHub Desktop.
CherryPy CORS issue
import cherrypy
import ConfigParser
import time
import json
from cherrypy.lib import static
import os
import cherrypy_cors
class Coordinator(object):
def __init__(self, config):
""" Coordinator object initialization.
:param config: ConfigParser object containing coordinator configuration
"""
self.config = config
@cherrypy.expose
@cherrypy.tools.json_in()
def add_meeting(self):
data = None
id = None
start_time = None
end_time = None
title = None
userlist = None
result = {"operation": "request", "result": "success"}
if cherrypy.request.method == "POST":
data = cherrypy.request.json
id = data["id"]
start_time = data["start_time"]
end_time = data["end_time"]
title = data["title"]
userlist = data["userlist"]
users = self.get_user_names()
temp_pref = 0
preference = None
temp = None
userstring= ""
for user in userlist:
if user not in users:
preference = "70 4000 1 1 " + user
self.add_user(user, preference)
temp_pref += 70
else:
preference = json.loads(self.get_preference(user))
temp = int(preference.split()[0])
temp_pref += temp
userstring += user
userstring += "__!__"
avgtemp = temp_pref / len(userlist)
# the rest involves adding the info above to database
return result
@cherrypy.expose
@cherrypy.tools.json_in()
def remove_meeting(self):
data = None
id = None
result = {"operation": "request", "result": "success"}
if cherrypy.request.method == "POST":
data = cherrypy.request.json
id = data["id"]
if id is not None:
# the rest involves deleting a meeting from the database
return result
def main():
config = ConfigParser.ConfigParser()
config.read(CONFIG_FILE) # config file contains host and port
port = config.getint('Meta', 'port')
host = config.get('Meta', 'host')
cherrypy_cors.install()
cherrypy.config.update({'server.socket_port': port,
'server.socket_host': host,
'cors.expose.on': True})
cherrypy.quickstart(Coordinator(config))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment