Python Forum
Why, TypeError: expected string or bytes-like object ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why, TypeError: expected string or bytes-like object ?
#4
You're passing v_inp as the string to examine for a pattern match via re.search(). But what you've posted doesn't show where that comes from (the actual function call). If what is passed in is not a string, then regex method will not like it.

>>> s1 = "foobar"  # a string
>>> s2 = 85        # not a string
>>> re.search(r"foo", s1)
<_sre.SRE_Match object; span=(0, 3), match='foo'>
>>> re.search(r"foo", s2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/re.py", line 182, in search
    return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object
You could possibly force it by coercing it to a string, but it's probably better to see what's calling it and if it's passing the right object.

>>> re.search(r"foo", str(s2))
>>>
Reply


Messages In This Thread
RE: Why, TypeError: expected string or bytes-like object ? - by bowlofred - May-08-2020, 04:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 410 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 522 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 758 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 1,016 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,382 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 6,846 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  boto3 - Error - TypeError: string indices must be integers kpatil 7 1,269 Jun-09-2023, 06:56 PM
Last Post: kpatil
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 2,044 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  TypeError: 'float' object is not callable #1 isdito2001 1 1,089 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: a bytes-like object is required ZeroX 13 4,178 Jan-07-2023, 07:02 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020