cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

MalformedInputException when using extended ascii characters in dbutils.notebook.exit()

jfpatenaude
New Contributor

I have a specific use case where I call another notebook using the 

dbutils.notebook.run() function. The other notebook do some processing and return a string in the dbutils.notebook.exit() function to the caller notebook. The returned string has some french special characters in it like ร , รฉ, รจ and because of that, the calling notebook executes for about 5 minutes longer than the called notebook and eventually ends with an exception: com.databricks.WorkflowException: java.nio.charset.MalformedInputException: Input length = 1

If I remove the special characters, everything works fine. Same thing If I use the .encode('ascii', 'remove') function on my string, but I need to have the the correct string returned with my accents. Is there a way to preserve my string intact? I'm on the Databricks Runtime Version 13.3 LTS.
 
You can reproduce the behavior using these two simple notebooks.
Caller Notebook:
output = dbutils.notebook.run('called_notebook', 600)
 
Called Notebook:
dbutils.notebook.exit("La mise ร  jour des tables des donnรฉes raffinรฉes est terminรฉe")
1 REPLY 1

jennie258fitz
New Contributor III

@jfpatenaude starbuckssecretmenu wrote:

I have a specific use case where I call another notebook using the 

dbutils.notebook.run() function. The other notebook do some processing and return a string in the dbutils.notebook.exit() function to the caller notebook. The returned string has some french special characters in it like ร , รฉ, รจ and because of that, the calling notebook executes for about 5 minutes longer than the called notebook and eventually ends with an exception: com.databricks.WorkflowException: java.nio.charset.MalformedInputException: Input length = 1

If I remove the special characters, everything works fine. Same thing If I use the .encode('ascii', 'remove') function on my string, but I need to have the the correct string returned with my accents. Is there a way to preserve my string intact? I'm on the Databricks Runtime Version 13.3 LTS.
 
You can reproduce the behavior using these two simple notebooks.
Caller Notebook:
output = dbutils.notebook.run('called_notebook', 600)
 
Called Notebook:
dbutils.notebook.exit("La mise ร  jour des tables des donnรฉes raffinรฉes est terminรฉe")

- Called Notebook

# Called Notebook
output_string = "La mise ร  jour des tables des donnรฉes raffinรฉes est terminรฉe"
# Encode to UTF-8
output_bytes = output_string.encode('utf-8')
## Convert to string format before returnin
dbutils.notebook.exit(output_bytes.decode('utf-8'))

- Caller Notebook

# Caller Notebook
output = dbutils.notebook.run('called_notebook', 600)
# You may want to ensure it's in the right format after calling
output_string = output.encode('utf-8').decode('utf-8')
print(output_string)

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now