{"id":22357,"date":"2020-09-08T13:41:19","date_gmt":"2020-09-08T20:41:19","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=22357"},"modified":"2023-12-01T03:59:32","modified_gmt":"2023-12-01T11:59:32","slug":"python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/","title":{"rendered":"Python TypeError: cannot use a string pattern on a bytes-like object Solution"},"content":{"rendered":"\n<p>You must provide a string to the <code>re<\/code> library if you want to manipulate an object using a string pattern. If you try to use a string pattern on an object which is stored using the \u201cbytes\u201d data type, you\u2019ll encounter the \u201cTypeError: cannot use a string pattern on a bytes-like object\u201d error.<br><\/p>\n\n\n\n<p>This guide talks about what this error means and why you may encounter it. We\u2019ll walk you through an example of this error so you can see what steps to take to resolve the error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">TypeError: cannot use a string pattern on a bytes-like object<\/h2>\n\n\n\n<p>Bytes objects contain a sequence of single bytes. They are immutable, like strings, which means they cannot be changed. A bytes object is typically returned when you read a binary file, or when you use a library like \u201crequest\u201d to retrieve data from a website.<br><\/p>\n\n\n\n<p>When you are using the <code>re<\/code> library, you must work either using bytes or objects. You cannot specify string patterns for a bytes object, and vice versa.<br><\/p>\n\n\n\n<p>If you are working with bytes data, your program must specify a regex pattern in bytes. If you are using regex with strings, provide a string-based regex pattern.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">An Example Scenario<\/h2>\n\n\n\n<p>We\u2019re going to write a program that retrieves the title of a web page. We work with the Career Karma website for this tutorial.<br><\/p>\n\n\n\n<p>To start, let\u2019s <a href=\"https:\/\/careerkarma.com\/blog\/python-import\/\">import the two libraries we\u2019ll need<\/a> to build our program: urllib and re.<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import urllib.request\nimport re<\/pre><\/div>\n\n\n\n<p>The <code>urllib<\/code> library lets us make web requests and the <code>re<\/code> library gives us the ability to use regex in our program.<br><\/p>\n\n\n\n<p>Next, we make a <a href=\"https:\/\/careerkarma.com\/blog\/what-is-http\/\">web request<\/a> to the Career Karma homepage:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>with urllib.request.urlopen(&quot;https:\/\/careerkarma.com&quot;) as res:\n         home = res.read()<\/pre><\/div>\n\n\n\n<p>The program retrieves the contents of the Career Karma homepage. This data is read using the <code>read()<\/code> method that is part of the <code>urlopen()<\/code> method. We store this data in the \u201cres\u201d <a href=\"https:\/\/careerkarma.com\/blog\/python-variables\/\">variable<\/a>.<br><\/p>\n\n\n\n<p>Now that we have the data from our program, use the <code>search()<\/code> method to find out the contents of the &lt;title&gt; tag on the web page that we have queried. This tag contains the title of a web page.<br><\/p>\n\n\n\n<p>To find the title of the web page, use the <code>re.search()<\/code> method:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>pattern = &quot;&lt;title&gt;(.*?)&lt;\/title&gt;&quot;\nfind_title = re.search(pattern, home)\n\nprint(&quot;The title of the web page is: {}.&quot;.format(find_title))<\/pre><\/div>\n\n\n\n<p>Our program will search for the contents of the &lt;title&gt; tag. Our program then prints the title of the web page to the console. We use the <a href=\"https:\/\/careerkarma.com\/blog\/python-f-string\/\">.format() method<\/a> to add this title into our string.&nbsp;<br><\/p>\n\n\n\n<p>Let\u2019s run our program and see if it works:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Traceback (most recent call last):\n File &quot;main.py&quot;, line 9, in &lt;module&gt;\n\t   find_title = re.search(pattern, home)\n File &quot;\/usr\/lib\/python3.8\/re.py&quot;, line 201, in search\n\t   return _compile(pattern, flags).search(string)\nTypeError: cannot use a string pattern on a bytes-like object<\/pre><\/div>\n\n\n\n<p>Our program fails to execute fully.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Solution<\/h2>\n\n\n\n<p>The value of \u201chome\u201d (the response from our web page) is a bytes object but the pattern we use to find the title of a web page is a string. This causes an error because we cannot match string patterns against bytes objects.<br><\/p>\n\n\n\n<p>There are two ways we can solve this problem.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Solution #1: Convert String Pattern to Bytes&nbsp;<\/h3>\n\n\n\n<p>We have to convert the string pattern we use to a bytes object. We can do this using either the \u201cb\u201d keyword or the <code>bytes()<\/code> method:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>pattern = b&quot;&lt;title&gt;(.*?)&lt;\/title&gt;&quot;\npattern = bytes(&quot;&lt;title&gt;(.*?)&lt;\/title&gt;&quot;)<\/pre><\/div>\n\n\n\n<p>The first method of using the \u201cb\u201d keyword is more common because it is easier to read. Now that we\u2019ve converted our string pattern to bytes, we can run our code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>The title of the web page is: &lt;re.Match object; span=(4037, 4124), match=b'&lt;title&gt;Career Karma - Discover the Best Career Ad&gt;.<\/pre><\/div>\n\n\n\n<p>Our code returns the text that matches our query.<br><\/p>\n\n\n\n<p>Now that we have the regex response, we could parse it so that it appears just as a string in our code. Parsing regex data is outside of the scope of this tutorial.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Solution #2: Decode Web Page Data<\/h3>\n\n\n\n<p>Alternatively, we could opt to decode our web page data to make it a string. This is useful if you expect a string for other parts of your code to work.<br><\/p>\n\n\n\n<p>We can decode our web page data by modifying the line of code where we open the web page:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>with urllib.request.urlopen(&quot;https:\/\/careerkarma.com&quot;) as res:\n        home = res.read().decode(&quot;utf-8&quot;)<\/pre><\/div>\n\n\n\n<p>This code will decode the response from our web request so that we can treat the response like a string. You should replace \u201cutf-8\u201d with the method of encoding the web page that you are requesting uses.<br><\/p>\n\n\n\n<p>We can then use a string pattern to search for the title tag. There is no need to convert our pattern to a bytes object because \u201chome\u201d will be a string value.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>pattern = &quot;&lt;title&gt;(.*?)&lt;\/title&gt;&quot;\nfind_title = re.search(pattern, home)\n\nprint(&quot;The title of the web page is: {}.&quot;.format(find_title))<\/pre><\/div>\n\n\n\n<p>Let\u2019s run our code and see what happens:&nbsp;<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>The title of the web page is: &lt;re.Match object; span=(4037, 4124), match='&lt;title&gt;Career Karma - Discover the Best Career Ad&gt;.<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The \u201cTypeError: cannot use a string pattern on a bytes-like object\u201d error is raised when you try to match a string pattern to an object which is stored using the bytes data type.<br><\/p>\n\n\n\n<p>You can fix this error either by converting your string pattern to a bytes object, or by converting the data with which you are working to a string object.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to fix this <a href=\"https:\/\/careerkarma.com\/blog\/how-long-to-learn-python\/\">Python error like a pro<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"You must provide a string to the re library if you want to manipulate an object using a string pattern. If you try to use a string pattern on an object which is stored using the \u201cbytes\u201d data type, you\u2019ll encounter the \u201cTypeError: cannot use a string pattern on a bytes-like object\u201d error. This guide&hellip;","protected":false},"author":240,"featured_media":22358,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-22357","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":[]},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>TypeError: cannot use a string pattern on a bytes-like | Career Karma<\/title>\n<meta name=\"description\" content=\"On Career Karma, learn the cause of and the solution to the TypeError: cannot use a string pattern on a bytes-like object Python error.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python TypeError: cannot use a string pattern on a bytes-like object Solution\" \/>\n<meta property=\"og:description\" content=\"On Career Karma, learn the cause of and the solution to the TypeError: cannot use a string pattern on a bytes-like object Python error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-08T20:41:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:59:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"765\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python TypeError: cannot use a string pattern on a bytes-like object Solution\",\"datePublished\":\"2020-09-08T20:41:19+00:00\",\"dateModified\":\"2023-12-01T11:59:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/\"},\"wordCount\":793,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/\",\"name\":\"TypeError: cannot use a string pattern on a bytes-like | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg\",\"datePublished\":\"2020-09-08T20:41:19+00:00\",\"dateModified\":\"2023-12-01T11:59:32+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"On Career Karma, learn the cause of and the solution to the TypeError: cannot use a string pattern on a bytes-like object Python error.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg\",\"width\":1020,\"height\":765},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/careerkarma.com\/blog\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python TypeError: cannot use a string pattern on a bytes-like object Solution\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"TypeError: cannot use a string pattern on a bytes-like | Career Karma","description":"On Career Karma, learn the cause of and the solution to the TypeError: cannot use a string pattern on a bytes-like object Python error.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/","og_locale":"en_US","og_type":"article","og_title":"Python TypeError: cannot use a string pattern on a bytes-like object Solution","og_description":"On Career Karma, learn the cause of and the solution to the TypeError: cannot use a string pattern on a bytes-like object Python error.","og_url":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-09-08T20:41:19+00:00","article_modified_time":"2023-12-01T11:59:32+00:00","og_image":[{"width":1020,"height":765,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python TypeError: cannot use a string pattern on a bytes-like object Solution","datePublished":"2020-09-08T20:41:19+00:00","dateModified":"2023-12-01T11:59:32+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/"},"wordCount":793,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/","url":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/","name":"TypeError: cannot use a string pattern on a bytes-like | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg","datePublished":"2020-09-08T20:41:19+00:00","dateModified":"2023-12-01T11:59:32+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"On Career Karma, learn the cause of and the solution to the TypeError: cannot use a string pattern on a bytes-like object Python error.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/09\/mimi-thian-8kdA2IJsjcU-unsplash.jpg","width":1020,"height":765},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-cannot-use-a-string-pattern-on-a-bytes-like-object\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python TypeError: cannot use a string pattern on a bytes-like object Solution"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/22357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=22357"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/22357\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/22358"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=22357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=22357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=22357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}