*** a/src/pl/plpython/plpython.c
--- b/src/pl/plpython/plpython.c
***************
*** 1059,1067 **** PLy_function_handler(FunctionCallInfo fcinfo, PLyProcedure *proc)
  				PLy_function_delete_args(proc);
  
  				if (has_error)
  					ereport(ERROR,
  							(errcode(ERRCODE_DATA_EXCEPTION),
! 						  errmsg("error fetching next item from iterator")));
  
  				fcinfo->isnull = true;
  				return (Datum) NULL;
--- 1059,1076 ----
  				PLy_function_delete_args(proc);
  
  				if (has_error)
+ 				{
+ 					PyObject	*ptype;
+ 					PyObject	*pvalue;
+ 					PyObject	*ptraceback;
+ 
+ 					PyErr_Fetch(&ptype, &pvalue, &ptraceback);
+ 
  					ereport(ERROR,
  							(errcode(ERRCODE_DATA_EXCEPTION),
! 						  errmsg("error fetching next item from iterator"),
! 						  errcontext(pvalue ? PyString_AsString(PyObject_Str(pvalue)) : 0)));
! 				}
  
  				fcinfo->isnull = true;
  				return (Datum) NULL;
