Discover this year's submissions to the Dataiku Frontrunner Awards and give kudos to your favorite use cases and success stories!READ MORE

Python debugging

Scobbyy2k3
Level 3
Level 3
Python debugging

i am using this code 

 

Job failed: Error in Python process: At line 19: <class 'TypeError'>: a bytes-like object is required, not 'str'

Please kindly help out

0 Kudos
3 Replies
CoreyS
Community Manager
Community Manager

Hi, @Scobbyy2k3 , thank you for posting! Can you provide any further details on the thread to assist users in helping you find a solution (insert examples like Dataiku version etc.)

Also, can you let us know if you’ve tried any fixes already?This should lead to a quicker response from the community.

Looking for more resources to help you use Dataiku effectively and upskill your knowledge? Check out these great resources: Dataiku Academy | Documentation | Knowledge Base

A reply answered your question? Mark as ‘Accepted Solution’ to help others like you!
0 Kudos
stevejohn
Level 1

The reason for this error is that in Python 3, strings are Unicode, but when transmitting on the network, the data needs to be bytes instead. We can convert bytes to string using bytes class decode() instance method, So you need to decode the bytes object to produce a string. In Python 3 , the default encoding is "utf-8" , so you can use directly:

b"python byte to string".decode("utf-8")

Python makes a clear distinction between bytes and strings . Bytes objects contain raw data — a sequence of octets — whereas strings are Unicode sequences . Conversion between these two types is explicit: you encode a string to get bytes, specifying an encoding (which defaults to UTF-8); and you decode bytes to get a string. Clients of these functions should be aware that such conversions may fail, and should consider how failures are handled.

 

CoreyS
Community Manager
Community Manager

Thank you for your response @stevejohn and welcome to the Dataiku Community! 

Looking for more resources to help you use Dataiku effectively and upskill your knowledge? Check out these great resources: Dataiku Academy | Documentation | Knowledge Base

A reply answered your question? Mark as ‘Accepted Solution’ to help others like you!
0 Kudos