Vocabulary data fetching

Guys,
Kindly help me with this query.

I have created a Choice field called "assigned_to" The values are fetched from the vocabulary.

vocabulary:
    def assignedTo(context):
    	assigned=[]
    	tokens_seen=set()
    	members=api.user.get_users(groupname='PFSAgent')
    	for member in members:
    		if member not in tokens_seen:
    			assigned.append(SimpleTerm(value=member,token=member,title=member))
    			tokens_seen.add(member)
    	return SimpleVocabulary(assigned)

field:

<field name="assigned_to" type="zope.schema.Choice">
      <description/>
      <required>False</required>
      <title>Assigned to</title>
      <vocabulary>fincrm.assignedTo</vocabulary>
    </field>

function to retrive data:

def loanrequestLink(self):
		loanreq=[]
		portal_catalog=api.portal.get_tool('portal_catalog')
		current_path=self.context.getPhysicalPath()
		current_path="/FinCRM/"+current_path[2]+"/"+current_path[3]+"/"+current_path[4]+"/"+current_path[5]
		brains=portal_catalog(portal_type="loan_request",path=current_path)
		for brain in brains:
			loan=brain.getObject()
			loanreq.append({
				"facility":loan.facility,
				"amount":loan.amount_in_crores,
				"roi":loan.roi,
				"requested_date":loan.requested_date,
				"loan_status":loan.loan_status,
				"requested_by":loan.requested_by,
				"assigned_to":loan.assigned_to,
			})
		return loanreq

page template:

<div tal:define="loanDet python:view.loanrequestLink()">
    <div tal:repeat="loan loanDet">
        <div class="col-sm-2">
    	    <h3 id="lab">Assigned To</h3>
    	    <td tal:content="loan/assigned_to">Assigned to</td>
        </div>
    </div>
</div> 

Error:
Here is the full error message:

Display traceback as text

Traceback (innermost last):

Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module Products.Five.browser.metaconfigure, line 485, in __call__
Module Products.Five.browser.pagetemplatefile, line 125, in __call__
Module Products.Five.browser.pagetemplatefile, line 59, in __call__
Module zope.pagetemplate.pagetemplate, line 132, in pt_render
Module five.pt.engine, line 93, in __call__
Module z3c.pt.pagetemplate, line 163, in render
Module chameleon.zpt.template, line 261, in render
Module chameleon.template, line 171, in render
Module a587c174ca6829d38941c16adb4a0cb0.py, line 1361, in render
Module c40646b487ea628523403a16502516ed.py, line 1223, in render_master
Module c40646b487ea628523403a16502516ed.py, line 420, in render_content
Module a587c174ca6829d38941c16adb4a0cb0.py, line 878, in __fill_content_core
Module a587c174ca6829d38941c16adb4a0cb0.py, line 107, in __quote
Module chameleon.zpt.template, line 243, in translate
Module z3c.pt.pagetemplate, line 152, in translate
Module chameleon.i18n, line 66, in fast_translate
Module zope.i18n, line 107, in translate
Module Products.CMFCore.MemberDataTool, line 369, in __str__
Module Products.CMFCore.MemberDataTool, line 273, in getMemberId
Module Products.CMFCore.MemberDataTool, line 264, in getUser
TypeError: exceptions must be old-style classes or derived from BaseException, not str

get_users() returns a list of MemberData object or user objects. It does not make sense to assign them directly to a SimpleTerm, neither as token nor as value nor as title. These should be strings or something similar but not member objects or whatever....store the member IDs inside the simple term and user the fullname of a member as title.

can you give me a sample code . It will be much more helpful.
I am new how to retrive teh ID and fullname of user

https://docs.plone.org/develop/plone/members/member_profile.html

thank you

There are several useful vocabularies in plone.app.vocabularies package. For Example https://github.com/plone/plone.app.vocabularies/blob/master/plone/app/vocabularies/users.py ... Check it out.

 token = userid.encode('unicode_escape') if isinstance(
        userid, six.text_type) else userid

What does this line do

I am using.

def projectAssignedTo(context):
	assigned=[]
	tokens_seen=set()
	members=api.user.get_users(groupname='bank')
	for member in members:
		username=member.getProperty('fullname',None)
		userId=member.getId()
		if member not in tokens_seen:
			assigned.append(SimpleTerm(value=username,token=username,title=userId))
			tokens_seen.add(member)
	return SimpleVocabulary(assigned)

I am recieving the same error even when I use:

assigned.append(SimpleTerm(value=userId,token=username,title=username))

Error:

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.autoform.view, line 45, in __call__
  Module plone.autoform.view, line 67, in _update
  Module z3c.form.group, line 52, in update
  Module z3c.form.group, line 48, in updateWidgets
  Module z3c.form.field, line 277, in update
  Module z3c.form.browser.select, line 51, in update
  Module z3c.form.browser.widget, line 171, in update
  Module z3c.form.widget, line 234, in update
  Module z3c.form.widget, line 132, in update
  Module z3c.form.converter, line 279, in toWidgetValue
  Module z3c.form.term, line 147, in getTerm
  Module z3c.form.term, line 157, in _makeMissingTerm
  Module z3c.form.util, line 50, in toUnicode
  Module Products.CMFCore.MemberDataTool, line 369, in __str__
  Module Products.CMFCore.MemberDataTool, line 273, in getMemberId
  Module Products.CMFCore.MemberDataTool, line 264, in getUser
TypeError: exceptions must be old-style classes or derived from BaseException, not str

It sets token to userid, if this is not unicode; otherwise, userid is converted to an ASCII string and then assigned to token. This is to ensure a restriction for vocabulary terms.

Can u Help me with the query

Likely, you a seeing two problems. The above one is likely a bug in Products.CMFCore.MemberDataTool (raising a bad exception). It is probably triggered by some unusual data.

I would approach the situation as follows: fix what is wrong in MemberDataTool. This hopefully will give you sufficient information to understand the initial problem.
Alternatively, you could use debugging (e.g. via Products.PDBDebugMode) to directly understand what MemberDataTool wants to complain about).

The problem is with the vocabulary in SimpleTerm() when I assign values as any one of the property. I am recieving this error.