These are chat archives for cherrypy/cherrypy

15th
Nov 2018
Giancarlos
@Giancarlos
Nov 15 2018 12:24
learned later that I only need the __metaclass__ = type line in the module Jaraco shared with me :)
Sviatoslav Sydorenko
@webknjaz
Nov 15 2018 12:24
yep
Giancarlos
@Giancarlos
Nov 15 2018 12:25
and by later I mean now LOL
Giancarlos
@Giancarlos
Nov 15 2018 13:23
having another issue now with arrays
for some reason jquery changes the param to be result_ids[] so I have to run this to get the array: result_ids = kwargs.pop('result_ids[]', [])
if I don't do **kwargs I get the following error: TypeError: post() got an unexpected keyword argument 'result_ids[]'
is there a good way for me to capture this array with CherryPy?
Sviatoslav Sydorenko
@webknjaz
Nov 15 2018 13:27
Well, you could move this to decorator level, where you'd substitute arg name, there's no other way. This might be smth we'd want to incorporate into the framework, though.
Giancarlos
@Giancarlos
Nov 15 2018 13:27
thought I had it working but then after I added the selectedmethod decorator it seems to not work the way it used to :(
looked at my JS to make sure I didn't derp that up, but looks like I havent touched it since
my real question is I guess: do I really need brackets for cherrypy to realize a parameter is an array?
if not, then I would try to change how jquery is sending it, cause this is annoying me lol
Giancarlos
@Giancarlos
Nov 15 2018 13:34
might have to ditch the decorator worse case so I can get this done for today and come back to this later sadly
Giancarlos
@Giancarlos
Nov 15 2018 13:50
yeah I tried it by not using the decorator and still have the same bug, so it might not be the decorator
basically I'm sending an array of strings, and for some reason CherryPy is sending over only the first letter in the first string in the array, which causes an error for me (it's an ObjectId for MongoDB)
image.png
image.png
so for some reason it is splitting up the string
oh wait...
Giancarlos
@Giancarlos
Nov 15 2018 13:58
I added a check to see if the variable is a string if it is I treat it as such, otherwise I treat it as an array, not sure why CherryPy decided to treat it inconsistently out of nowhere... I know I tested both cases
Sviatoslav Sydorenko
@webknjaz
Nov 15 2018 16:30
it's treated just like it arrives
it's not turning that into array AFAIR
Giancarlos
@Giancarlos
Nov 15 2018 18:11
I'm just glad I found a good way to handle it
you guys do great work, CherryPy is my go-to web framework :)
Sviatoslav Sydorenko
@webknjaz
Nov 15 2018 18:30
:+1:
Giancarlos
@Giancarlos
Nov 15 2018 20:48
what's the sane way of enabling CORS in 2018 for CherryPy?
I'm not seeing any indication in devtools
Giancarlos
@Giancarlos
Nov 15 2018 20:55
conf = {
    '/': {
        'tools.response_headers.on': True,
        'tools.response_headers.headers': [('Cache-Control', 'no-cache, no-store, must-revalidate'),
                                           ('Pragma', 'no-cache'),
                                           ('Access-Control-Allow-Origin', '*')],
        'tools.CORS.on': True
    }
}
tried that but I'm not seeing it, oddly enough seeing the other headers