[New-bugs-announce] [issue45087] Confusing error message when trying split bytes.

Alex Zaslavskis report at bugs.python.org
Thu Sep 2 15:37:44 EDT 2021


New submission from Alex Zaslavskis <sahsariga111 at gmail.com>:

If we will try to split bytes we will got quite strange error in console. 

Traceback (most recent call last):
  File "C:/Users/ProAdmin/Desktop/bug_in_python.py", line 6, in <module>
    byte_message.split(",")
TypeError: a bytes-like object is required, not 'str'

The problem here is that object should be string and in if I convert it to string the error is going. So that mean that there are error in mistake . Correct variant should be :
Traceback (most recent call last):
  File "C:/Users/ProAdmin/Desktop/bug_in_python.py", line 6, in <module>
    byte_message.split(",")
TypeError:  str is required, not a bytes-like object


message = 'Python is fun'
byte_message = bytes(message, 'utf-8')
print(byte_message)
#byte_message.split(",") causes error
str(byte_message).split(",") # works

----------
components: Argument Clinic
files: bug_in_python.py
messages: 400948
nosy: larry, sahsariga111
priority: normal
severity: normal
status: open
title: Confusing error message when trying split bytes.
type: compile error
versions: Python 3.9
Added file: https://bugs.python.org/file50257/bug_in_python.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45087>
_______________________________________


More information about the New-bugs-announce mailing list