8

I would like to pass a list as parameter to flask via getlist(). Reading here: REST API Best practice: How to accept list of parameter values as input

Could you help figuring out why this simple code failed to read a list parameter (skip_id) ?

def api_insight(path):
    import pdb
    skip_id = request.args.getlist('skip_id', type=None)
    print( 'skip_id', skip_id)
    pdb.set_trace()

curl http://myexample.com/<mypath>/?&skip_id=ENSG00000100030,ENSG00000112062  
# empty list


curl http://myexample.com/<mypath>/?&skip_id=[ENSG00000100030,ENSG00000112062]
# empty list

curl http://myexample.com/<mypath>/?&skip_id=ENSG00000100030&skip_id=ENSG00000
# only first value is read in list
Community
  • 1
  • 1
user305883
  • 1,635
  • 2
  • 24
  • 48

1 Answers1

4

The last way should actually work. I just tried it in my Browser.

http://localhost:5000/api?skip_id=ENSG000001000301&skip_id=ENSG00000

Gives me

['ENSG00000100030', 'ENSG00000']

However with curl you will get into trouble with the & character as it will put the task in the background (at least if you're on Linux). With curl you can use

curl -X GET -G http://localhost:5000/api?skip_id -d skip_id=ENSG00000100030 -d skip_id=ENSG00000

to get your described result.

MrLeeh
  • 5,321
  • 6
  • 33
  • 51