Error: Can't convert 'bytes' object to str implicitly

I have been building a form using xls and during validation using the XLS form converter on the ODK website I got the error message:

Error: Can't convert 'bytes' object to str implicitly

Most of the error messages are very clear and easy to fix, but this one has me stuck.

What is the 'bytes' object referred to and what does str mean.

Thank you in advance for any help with this.

Keith.

1 Like

Hi @wkgray

please attach your form because it's difficoult to find out what's wrong when you can't see the file.

Regards,
Grzegorz

Hi Grzegorz

I am a new user, so cannot upload my form, is there any way round this?

Ohh I see so use https://uploadfiles.io/ for example and paste a link here.

It should be available here

https://ufile.io/7gocb

The reply above wasn't an answer to the initial question, just the dataset. I'm wondering if there is an answer for what the issue is when you get this error...

Error: Can't convert 'bytes' object to str implicitly
getting the above error each time am trying to convert an excel file.

1 Like

It looks like @plaga is getting the same error so I've joined the topics.

I haven't seen this specific error before. My guess would be that a special character that is being interpreted as binary made its way into the form. A strategy similar to the one at Conversion Error (ascii codec can't decode...) may be needed to find where and fix it.

It would really help to have a form to refer to but unfortunately the form link seems to have expired. @wkgray you should be able to upload now or perhaps one of @amarr or @plaga can.

Please what are 'bytes' object. can we have examples pls?

Hello! When I had this issue, it was because I accidentally had a space in one of my variable names. Once I changed this, my issue was resolved.

1 Like

I think this was an temporary error with the conversion software rather than my form as I did not get it again and it has not been an issue. It is possible that it was due to a space in one of the variable names, and this seems the most obvious explanation if it was not just a temporary issue with the conversion.

Thank you everyone for your help.

Keith

1 Like

The python interpreter at open data kit webchecker checks the compliance of the xls form to certain rules, and one of the rare but annoying error is" Can't convert 'byte' object to str implicitly, usually occurs when you have a space or illegal character under the 'name' column in xls form. To find out the offending character you can divide the excel sheets using divide and conquer kind of algorithm, test smaller part say one half of the form and the other half separately, continue testing the error on untested half of the excel till you get the problem.

4 Likes

I've had this problem and have been doing some heuristics (um, trial and error) to find the cause. I searched my xlsx Name columns for 'special characters' and spaces, but found none.

However, I did discover that if the name column in the survey sheet has a number in it, the error comes up. Is this expected behaviour? It's unfortunate, because I had used the questions as the Name (my survey is being run in parallel online), but they were too long so thought using the question numbers would be easy...

My workaround is to spell the numbers!
I found the following values in the Name column:
1 - failed
1a - failed
one - succeeded
one_a - succeeded

If I use numbers in the name column on the Choices sheet the xlsform converts no problem.

Not exactly intuitive but on a long survey it's not always easy to find 'shorthand' names for each question. It would be good if numbers could be used...

One thing we tend to do in surveys is systematically use q# (q100, q2207) as variable names for questions that the enumerators see. Then we always know if something is a q# variable it is coming from the original question asked. Anything we calculate (say, for checks) we give a different name, like z#. This is also handy for when you are analyzing the resulting dataset in a statistical program (STATA person here), because you can always tell a created variable from an original variable; original variables are the q# while the created ones we name things like "age."

This doesn't solve the underlying problem of numbers failing, but might be a helpful way to systematically number!

1 Like

@seewhy pyxform, the library that converts XLSForms to XForms, uses the name column to generate an XML node and per the XML spec, XML nodes can't start with numbers.

The latest versions of the XLSForm converters should give you this error if you have a name that starts with a a number: pyxform.errors.PyXFormError: [row : 2] Invalid question name [1] Names must begin with a letter, colon, or underscore. Subsequent characters can include numbers, dashes, and periods.

What tool and version are you using to do the conversion?

1 Like

Hi @elmps2018 and @yanokwa,
Thanks for your responses - between them there is a solution that works and matches those criteria for pyxform.
I did check the documentation (http://xlsform.org/) but it didn't leap out at me that the name can't start with a number (or be a number). Maybe I was looking in the wrong place.

Now I know, it is easy to avoid, and still have a logical naming convention, such as that suggested by @elmps2018

I'm using the online converter (the one that I'm having trouble with in Firefox!) but it doesn't give me the explicit error you have posted. Which is why I posted my question in this thread.

Thanks very much to both of you for your help - appreciated.

1 Like

Efectivamente mi estimado Martin, me estaba saliendo este error y era porque tenia uno de los nombres de las variables con una tilde.

Gracias por tu apreciación.

1 Like

@luis_gabriel_Bohorqu Me alegro de que haya recibido ayuda, éxito en su proyecto.
Muchas gracias

1 Like

Thanks for all the great troubleshooting on this thread! I've just confirmed that there's a bug in the current version of XLSForm online available at http://opendatakit.org/xiframe/. It should show the error that @yanokwa mentioned above (pyxform.errors.PyXFormError: [row : 2] Invalid question name [1] Names must begin with a letter, colon, or underscore. Subsequent characters can include numbers, dashes, and periods.). I have filed the issue at https://github.com/opendatakit/xlsform-online/issues/5.

1 Like

any label within name column should not started with a number digit... this one of the reason for "Error: Can't convert 'bytes' object to str implicitly" this error massage....

Thanks