# Uncaught exception in exposed API method:

**URL:** <https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668>\
**Category:** Uncategorized\
**Tags:** development-tools, dropbox\
**Created:** [March 11, 2022, 5:54am UTC](https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668 "2022-03-11T05:54:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![george.weingart](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/george.weingart/32/1770_2.png) [@george.weingart](https://help.galaxyproject.org/u/george.weingart)\
**Post date:** [March 11, 2022, 5:54am UTC](https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668/1 "2022-03-11T05:54:58Z")

</div>

Hello,  
I am encountering an error in a tool I am developing:

galaxy.web.framework.decorators ERROR 2022-03-11 05:38:11,051 [p:4087,w:1,m:0] [uWSGIWorker1Core0] Uncaught exception in exposed API method:  
Traceback (most recent call last):  
File “lib/galaxy/web/framework/decorators.py”, line 295, in decorator  
rval = func(self, trans, \*args, \*\*kwargs)  
File “lib/galaxy/webapps/galaxy/api/tools.py”, line 123, in build  
return tool.to\_json(trans, kwd.get(‘inputs’, kwd))  
File “lib/galaxy/tools/ **init**.py”, line 2111, in to\_json  
populate\_state(request\_context, self.inputs, params. **dict** , state\_inputs, state\_errors)  
File “lib/galaxy/tools/parameters/ **init**.py”, line 316, in populate\_state  
state[input.name] = input.get\_initial\_value(request\_context, context)  
File “lib/galaxy/tools/parameters/basic.py”, line 921, in get\_initial\_value  
value = [optval for \_, optval, selected in options if selected]  
File “lib/galaxy/tools/parameters/basic.py”, line 921, in   
value = [optval for \_, optval, selected in options if selected]  
ValueError: too many values to unpack (expected 3)

The relevant portion of xml looks as follows:

` 
    
    
    
    
    
                
                
```
            <param name="batch" label="Name of the batch variable" type='select' dynamic_options="mmuphin_get_cols(data)" />
            <param name="covariates" type="text" format="text" value="study_condition" label="Name(s) of covariates to adjust for in the batch correction model"/>

</inputs>
<outputs>
    <data name="output1" format="csv" label="Adjusted abundance table" />
    <data name="output2" format="pdf" label="Adjust batch diagnostic" />
</outputs>
<help><![CDATA[

```
etc. etc. on the xml
The code I invoke in the program looks as follows:
from galaxy import datatypes, model
import sys
import string
import csv
#############################################################
# Progran to read the first row of the metadata
# and populate the fields in the panel
# Written by George Weingart 2022/03/10
#############################################################
def mmuphin_get_cols(data):
if data == “”:
return 
fname = data.dataset.file_name
lMetadata_Colnames = list()
f = open(fname)
csv_reader = csv.reader(f)
line_cntr = -1
for line in csv_reader:
line_cntr+=1
if line_cntr > 0:
return lMetadata_Colnames
lMetadata_Colnames = [x for x in line if x]
f.close()
return lMetadata_Colnames
I know the is not advises / deprecated, so maybe someone can provide a better way to do what we need, which is:

We want to populate a field so that it presents a dropbox selection.
The dropbox is populated from the first row of a csv file that the user presents in the
 
file.
For example:
The first two lines of a sample file are as follows:
“”,“subjectID”,“body_site”,“study_condition”,“disease”,“age_category”,“country”,“non_westernized”,“DNA_extraction_kit”,“number_reads”,“number_bases”,“minimum_read_length”,“median_read_length”,“curator”,“NCBI_accession”,“antibiotics_current_use”,“disease_subtype”,“age”,“gender”,“BMI”,“tnm”,“hdl”,“triglycerides”,“hba1c”,“ldl”,“location”,“ajcc”,“fobt”,“studyID”
“FengQ_2015.metaphlan_bugs_list.stool:SID31004”,“SID31004”,“stool”,“CRC”,“CRC;fatty_liver;hypertension”,“adult”,“AUT”,“no”,“MoBio”,40898340,3649611221,30,93,“Paolo_Manghi;Marisa_Metzger”,“ERR688505;ERR688358”,NA,“carcinoma”,64,“male”,29.35,“t1n0m0”,28,172,5.2,92,NA,NA,NA,“FengQ_2015.metaphlan_bugs_list.stool”
“FengQ_2015.metaphlan_bugs_list.stool:SID31009”,“SID31009”,“stool”,“control”,“fatty_liver;hypertension”,“senior”,“AUT”,“no”,“MoBio”,66107961,6196998053,30,96,“Paolo_Manghi;Marisa_Metzger”,“ERR688506;ERR688359”,NA,NA,68,“male”,32,NA,50,101,NA,157,NA,NA,NA,“FengQ_2015.metaphlan_bugs_list.stool”
We need it to generate a drop down box that looks as follows:
subjectID
body_site
study_condition
disease
age_category
country
non_westernized
DNA_extraction_kit
number_reads
number_bases
minimum_read_length
median_read_length
curator
NCBI_accession
antibiotics_current_use
disease_subtype
age
gender
BMI
tnm
hdl
triglycerides
hba1c
ldl
location
ajcc
fobt
studyID
Can anyone suggest how to do it without the
   ?

Otherwise, can someone point me at the current problem ?
Thanks!`

---

<div class="post-metadata">

**Author:** ![jennaj](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/jennaj/32/27_2.png) [@jennaj](https://help.galaxyproject.org/u/jennaj)\
**Post date:** [March 11, 2022, 7:51pm UTC](https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668/2 "2022-03-11T19:51:22Z")

</div>

Hi @george.weingart

Have you seen the tool development tutorials here?

> **[Galaxy Training: Development in Galaxy](https://training.galaxyproject.org/training-material/topics/dev/)**
>
> Galaxy is an open-source project. Everyone can contribute...

---

<div class="post-metadata">

**Author:** ![george.weingart](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/george.weingart/32/1770_2.png) [@george.weingart](https://help.galaxyproject.org/u/george.weingart)\
**Post date:** [March 11, 2022, 8:02pm UTC](https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668/3 "2022-03-11T20:02:34Z")

</div>

Yes.  
Any concrete advice?

---

<div class="post-metadata">

**Author:** ![jennaj](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/jennaj/32/27_2.png) [@jennaj](https://help.galaxyproject.org/u/jennaj)\
**Post date:** [March 12, 2022, 12:04am UTC](https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668/4 "2022-03-12T00:04:01Z")

</div>

Hi @george.weingart

No, I don’t personally have advice for this one except to make sure you are using `Planemo` for tool development.

There isn’t another tool that I know of that interprets a comment line from a single input dataset to _dynamically_ construct tool form labels directly. It may not be possible, and the tool itself needs to have the input columns defined before manipulations are applied. Tools that may seem to be interpreting metadata are getting that information from a defined datatype, not from the input dataset itself.

You could explore the “tool factory” tool. It is a tool that creates other tools, then the created tool is what is deployed for end users (not the tool factory tool itself). If that seems useful, there are tutorials at that link I sent.

There are also many tools already that can filter any input `tabular`/`csv` dataset, but that doesn’t seem to be what you are trying to do. Or, maybe you could consider using that functionality. Meaning, create a workflow that contains filtering tools with some options/parameters pre-set and others adjustable at runtime. That could be shared with others to standardize the functionality.

The `Upload` tool can also be used to format/filter datasets with the “Rule Builder” functions (interprets comment/metadata lines), but that also doesn’t seem to be the goal and wouldn’t involve a distinct/new “tool”. And for data in a dataset collection, “rules” can also be applied based on the collection’s metadata – but again that doesn’t seem to fit the use case/goal.

Maybe someone else has more advice…

---

<div class="post-metadata">

**Author:** ![george.weingart](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/george.weingart/32/1770_2.png) [@george.weingart](https://help.galaxyproject.org/u/george.weingart)\
**Post date:** [March 12, 2022, 7:03am UTC](https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668/5 "2022-03-12T07:03:59Z")

</div>

Thank you !  
Unfortunately, this does not solve my problem.  
I can summarize the issue as follows:

1. I have a comma delimited file containing many lines.
2. The first line contains alphabetic headers
3. I want to populate a param so it is a drop down box, each row contains the name of the corresponding column, so that the User can select a parm which consists of the name of the column he might choose.

**All I need is how to code the \<param for that.**

For example, as I mentioned before:  
If the first two lines of my sample file are:

**“”,“subjectID”,“body\_site”,“study\_condition”,“disease”,“age\_category”,“country”,“non\_westernized”,“DNA\_extraction\_kit”,“number\_reads”,“number\_bases”,“minimum\_read\_length”,“median\_read\_length”,“curator”,“NCBI\_accession”,“antibiotics\_current\_use”,“disease\_subtype”,“age”,“gender”,“BMI”,“tnm”,“hdl”,“triglycerides”,“hba1c”,“ldl”,“location”,“ajcc”,“fobt”,“studyID”**  
“FengQ\_2015.metaphlan\_bugs\_list.stool:SID31004”,“SID31004”,“stool”,“CRC”,“CRC;fatty\_liver;hypertension”,“adult”,“AUT”,“no”,“MoBio”,40898340,3649611221,30,93,“Paolo\_Manghi;Marisa\_Metzger”,“ERR688505;ERR688358”,NA,“carcinoma”,64,“male”,29.35,“t1n0m0”,28,172,5.2,92,NA,NA,NA,“FengQ\_2015.metaphlan\_bugs\_list.stool”  
“FengQ\_2015.metaphlan\_bugs\_list.stool:SID31009”,“SID31009”,“stool”,“control”,“fatty\_liver;hypertension”,“senior”,“AUT”,“no”,“MoBio”,66107961,6196998053,30,96,“Paolo\_Manghi;Marisa\_Metzger”,“ERR688506;ERR688359”,NA,NA,68,“male”,32,NA,50,101,NA,157,NA,NA,NA,“FengQ\_2015.metaphlan\_bugs\_list.stool”

Then, I want to populate the drop down box with:

**subjectID**  
**body\_site**  
**study\_condition**  
**disease**  
**age\_category**  
**country**  
**non\_westernized**  
**DNA\_extraction\_kit**  
**number\_reads**  
**number\_bases**  
**minimum\_read\_length**  
**median\_read\_length**  
**curator**  
**NCBI\_accession**  
**antibiotics\_current\_use**  
**disease\_subtype**  
**age**  
**gender**  
**BMI**  
**tnm**  
**hdl**  
**triglycerides**  
**hba1c**  
**ldl**  
**location**  
**ajcc**  
**fobt**  
**studyID**

So that the User selects one of those values for the process.

---

<div class="post-metadata">

**Author:** ![george.weingart](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/george.weingart/32/1770_2.png) [@george.weingart](https://help.galaxyproject.org/u/george.weingart)\
**Post date:** [March 14, 2022, 6:41pm UTC](https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668/6 "2022-03-14T18:41:44Z")

</div>

Hi Jennaj !  
Thanks for your reply.  
At the end, I solved it in two steps:

1. I present the User with a screen to upload his csv file, use python to take the first row, split it and generate a tabulate file, each row contains one of the elements of the split (I called the file ‘metadata\_headers’)
2. I present the User with the screen, but added the following:

```auto

<param name="metadata_headers" type="data" label="Covariates" format="mmuphin_metadata_headers" help="Name(s) of covariates to adjust for in the batch correction model"/>

<param name="covariates" type="select" optional="true" multiple="true" label="Covariates - Please select from the drop down menu">
 		         <options from_dataset="metadata_headers">
       				 <column name="name" index="0"/>
        			<column name="value" index="0"/>
    			</options>
</param>

```

It works.  
Would be nice if I knew how to do it in one step, but this works.  
Thanks again,  
George

---

<div class="post-metadata">

**Author:** ![george.weingart](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/george.weingart/32/1770_2.png) [@george.weingart](https://help.galaxyproject.org/u/george.weingart)\
**Post date:** [March 14, 2022, 6:42pm UTC](https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668/7 "2022-03-14T18:42:51Z")

</div>

For some reason the code doesn’t show…  
Here it is:

```
<param name="metadata_headers" type="data" label="Covariates" format="mmuphin_metadata_headers" help="Name(s) of covariates to adjust for in the batch correction model"/>

	<param name="batch" type="select" optional="true" multiple="true" label="Batch - Please select from the drop down menu">
                     <options from_dataset="metadata_headers">
                             <column name="name" index="0"/>
                            <column name="value" index="0"/>
                    </options>
            </param>

	<param name="covariates" type="select" optional="true" multiple="true" label="Covariates - Please select from the drop down menu">
	         <options from_dataset="metadata_headers">
   				 <column name="name" index="0"/>
    			<column name="value" index="0"/>
			</options>
		</param>
```

---

<div class="post-metadata">

**Author:** ![jennaj](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/jennaj/32/27_2.png) [@jennaj](https://help.galaxyproject.org/u/jennaj)\
**Post date:** [March 17, 2026, 5:55am UTC](https://help.galaxyproject.org/t/uncaught-exception-in-exposed-api-method/7668/8 "2026-03-17T05:55:30Z")

</div>

Closed on March 17, 2026, 5:55am UTC


