0

Getting error : Conflict between bytes and str type

old_server_uuid = p3.communicate()[0].split("|")[1].strip()

Getting the below error:

Traceback (most recent call last):
  File "create_env_file.py", line 68, in <module>
    data = create_env_source_list(node_name, ip_address)
  File "create_env_file.py", line 14, in create_env_source_list
    raise(ex)
  File "create_env_file.py", line 12, in create_env_source_list
    old_server_uuid = p3.communicate()[0].split("|")[1].strip()
TypeError: a bytes-like object is required, not 'str'

1 Answer 1

1

Python 3 doesn't allow mixing text (Unicode) strings and byte strings.

the result of p3.communicate()[0] is a byte string, so the .split argument must be one as well.

Examples:

Splitting a byte string with a Unicode string:

>>> b'abc|123'.split('|')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required, not 'str'

Splitting a byte string with a byte string:

>>> b'abc|123'.split(b'|')
[b'abc', b'123']
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.