We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Shortly example cannot redirect to the expected link
**Bug**

In Shortly example, if I want to follow a short link with  `http://127.0.0.1:5000/1`, the following error occurs:

```
Traceback (most recent call last):
  File "/werkzeug/src/werkzeug/serving.py", line 319, in run_wsgi
    execute(self.server.app)
  File "/werkzeug/src/werkzeug/serving.py", line 308, in execute
    application_iter = app(environ, start_response)
  File "/werkzeug/examples/shortly/shortly.py", line 121, in __call__
    return self.wsgi_app(environ, start_response)
  File "/werkzeug/src/werkzeug/middleware/shared_data.py", line 287, in __call__
    return self.app(environ, start_response)
  File "/werkzeug/examples/shortly/shortly.py", line 117, in wsgi_app
    response = self.dispatch_request(request)
  File "/werkzeug/examples/shortly/shortly.py", line 109, in dispatch_request
    return getattr(self, f"on_{endpoint}")(request, **values)
  File "/werkzeug/examples/shortly/shortly.py", line 72, in on_follow_short_link
    return redirect(link_target)
  File "/werkzeug/src/werkzeug/utils.py", line 554, in redirect
    display_location = html.escape(location)
  File "/.pyenv/versions/3.8.10/lib/python3.8/html/__init__.py", line 19, in escape
    s = s.replace("&", "&amp;") # Must be done first!
TypeError: a bytes-like object is required, not 'str'
```

**Expected Behavior**

The browser should redirect to the link based on the short id.

**Reason**

redis-py package saves value as string but returns bytes by default. The `link_target` is bytes at the moment, but str is needed for `redirect` function

**Environment:**

- Python version: 3.8.10
- Werkzeug version: 2.0.1
- Redis-py version: 3.5.3

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `examples/shortly/shortly.py`
Content:
```
1 """A simple URL shortener using Werkzeug and redis."""
2 import os
3 
4 import redis
5 from jinja2 import Environment
6 from jinja2 import FileSystemLoader
7 from werkzeug.exceptions import HTTPException
8 from werkzeug.exceptions import NotFound
9 from werkzeug.middleware.shared_data import SharedDataMiddleware
10 from werkzeug.routing import Map
11 from werkzeug.routing import Rule
12 from werkzeug.urls import url_parse
13 from werkzeug.utils import redirect
14 from werkzeug.wrappers import Request
15 from werkzeug.wrappers import Response
16 
17 
18 def base36_encode(number):
19     assert number >= 0, "positive integer required"
20     if number == 0:
21         return "0"
22     base36 = []
23     while number != 0:
24         number, i = divmod(number, 36)
25         base36.append("0123456789abcdefghijklmnopqrstuvwxyz"[i])
26     return "".join(reversed(base36))
27 
28 
29 def is_valid_url(url):
30     parts = url_parse(url)
31     return parts.scheme in ("http", "https")
32 
33 
34 def get_hostname(url):
35     return url_parse(url).netloc
36 
37 
38 class Shortly:
39     def __init__(self, config):
40         self.redis = redis.Redis(config["redis_host"], config["redis_port"])
41         template_path = os.path.join(os.path.dirname(__file__), "templates")
42         self.jinja_env = Environment(
43             loader=FileSystemLoader(template_path), autoescape=True
44         )
45         self.jinja_env.filters["hostname"] = get_hostname
46 
47         self.url_map = Map(
48             [
49                 Rule("/", endpoint="new_url"),
50                 Rule("/<short_id>", endpoint="follow_short_link"),
51                 Rule("/<short_id>+", endpoint="short_link_details"),
52             ]
53         )
54 
55     def on_new_url(self, request):
56         error = None
57         url = ""
58         if request.method == "POST":
59             url = request.form["url"]
60             if not is_valid_url(url):
61                 error = "Please enter a valid URL"
62             else:
63                 short_id = self.insert_url(url)
64                 return redirect(f"/{short_id}+")
65         return self.render_template("new_url.html", error=error, url=url)
66 
67     def on_follow_short_link(self, request, short_id):
68         link_target = self.redis.get(f"url-target:{short_id}")
69         if link_target is None:
70             raise NotFound()
71         self.redis.incr(f"click-count:{short_id}")
72         return redirect(link_target)
73 
74     def on_short_link_details(self, request, short_id):
75         link_target = self.redis.get(f"url-target:{short_id}")
76         if link_target is None:
77             raise NotFound()
78         click_count = int(self.redis.get(f"click-count:{short_id}") or 0)
79         return self.render_template(
80             "short_link_details.html",
81             link_target=link_target,
82             short_id=short_id,
83             click_count=click_count,
84         )
85 
86     def error_404(self):
87         response = self.render_template("404.html")
88         response.status_code = 404
89         return response
90 
91     def insert_url(self, url):
92         short_id = self.redis.get(f"reverse-url:{url}")
93         if short_id is not None:
94             return short_id
95         url_num = self.redis.incr("last-url-id")
96         short_id = base36_encode(url_num)
97         self.redis.set(f"url-target:{short_id}", url)
98         self.redis.set(f"reverse-url:{url}", short_id)
99         return short_id
100 
101     def render_template(self, template_name, **context):
102         t = self.jinja_env.get_template(template_name)
103         return Response(t.render(context), mimetype="text/html")
104 
105     def dispatch_request(self, request):
106         adapter = self.url_map.bind_to_environ(request.environ)
107         try:
108             endpoint, values = adapter.match()
109             return getattr(self, f"on_{endpoint}")(request, **values)
110         except NotFound:
111             return self.error_404()
112         except HTTPException as e:
113             return e
114 
115     def wsgi_app(self, environ, start_response):
116         request = Request(environ)
117         response = self.dispatch_request(request)
118         return response(environ, start_response)
119 
120     def __call__(self, environ, start_response):
121         return self.wsgi_app(environ, start_response)
122 
123 
124 def create_app(redis_host="localhost", redis_port=6379, with_static=True):
125     app = Shortly({"redis_host": redis_host, "redis_port": redis_port})
126     if with_static:
127         app.wsgi_app = SharedDataMiddleware(
128             app.wsgi_app, {"/static": os.path.join(os.path.dirname(__file__), "static")}
129         )
130     return app
131 
132 
133 if __name__ == "__main__":
134     from werkzeug.serving import run_simple
135 
136     app = create_app()
137     run_simple("127.0.0.1", 5000, app, use_debugger=True, use_reloader=True)
138
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/shortly/shortly.py b/examples/shortly/shortly.py
--- a/examples/shortly/shortly.py
+++ b/examples/shortly/shortly.py
@@ -37,7 +37,9 @@
 
 class Shortly:
     def __init__(self, config):
-        self.redis = redis.Redis(config["redis_host"], config["redis_port"])
+        self.redis = redis.Redis(
+            config["redis_host"], config["redis_port"], decode_responses=True
+        )
         template_path = os.path.join(os.path.dirname(__file__), "templates")
         self.jinja_env = Environment(
             loader=FileSystemLoader(template_path), autoescape=True

{"golden_diff": "diff --git a/examples/shortly/shortly.py b/examples/shortly/shortly.py\n--- a/examples/shortly/shortly.py\n+++ b/examples/shortly/shortly.py\n@@ -37,7 +37,9 @@\n \n class Shortly:\n     def __init__(self, config):\n-        self.redis = redis.Redis(config[\"redis_host\"], config[\"redis_port\"])\n+        self.redis = redis.Redis(\n+            config[\"redis_host\"], config[\"redis_port\"], decode_responses=True\n+        )\n         template_path = os.path.join(os.path.dirname(__file__), \"templates\")\n         self.jinja_env = Environment(\n             loader=FileSystemLoader(template_path), autoescape=True\n", "issue": "Shortly example cannot redirect to the expected link\n**Bug**\r\n\r\nIn Shortly example, if I want to follow a short link with  `http://127.0.0.1:5000/1`, the following error occurs:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/werkzeug/src/werkzeug/serving.py\", line 319, in run_wsgi\r\n    execute(self.server.app)\r\n  File \"/werkzeug/src/werkzeug/serving.py\", line 308, in execute\r\n    application_iter = app(environ, start_response)\r\n  File \"/werkzeug/examples/shortly/shortly.py\", line 121, in __call__\r\n    return self.wsgi_app(environ, start_response)\r\n  File \"/werkzeug/src/werkzeug/middleware/shared_data.py\", line 287, in __call__\r\n    return self.app(environ, start_response)\r\n  File \"/werkzeug/examples/shortly/shortly.py\", line 117, in wsgi_app\r\n    response = self.dispatch_request(request)\r\n  File \"/werkzeug/examples/shortly/shortly.py\", line 109, in dispatch_request\r\n    return getattr(self, f\"on_{endpoint}\")(request, **values)\r\n  File \"/werkzeug/examples/shortly/shortly.py\", line 72, in on_follow_short_link\r\n    return redirect(link_target)\r\n  File \"/werkzeug/src/werkzeug/utils.py\", line 554, in redirect\r\n    display_location = html.escape(location)\r\n  File \"/.pyenv/versions/3.8.10/lib/python3.8/html/__init__.py\", line 19, in escape\r\n    s = s.replace(\"&\", \"&amp;\") # Must be done first!\r\nTypeError: a bytes-like object is required, not 'str'\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nThe browser should redirect to the link based on the short id.\r\n\r\n**Reason**\r\n\r\nredis-py package saves value as string but returns bytes by default. The `link_target` is bytes at the moment, but str is needed for `redirect` function\r\n\r\n**Environment:**\r\n\r\n- Python version: 3.8.10\r\n- Werkzeug version: 2.0.1\r\n- Redis-py version: 3.5.3\n", "before_files": [{"content": "\"\"\"A simple URL shortener using Werkzeug and redis.\"\"\"\nimport os\n\nimport redis\nfrom jinja2 import Environment\nfrom jinja2 import FileSystemLoader\nfrom werkzeug.exceptions import HTTPException\nfrom werkzeug.exceptions import NotFound\nfrom werkzeug.middleware.shared_data import SharedDataMiddleware\nfrom werkzeug.routing import Map\nfrom werkzeug.routing import Rule\nfrom werkzeug.urls import url_parse\nfrom werkzeug.utils import redirect\nfrom werkzeug.wrappers import Request\nfrom werkzeug.wrappers import Response\n\n\ndef base36_encode(number):\n    assert number >= 0, \"positive integer required\"\n    if number == 0:\n        return \"0\"\n    base36 = []\n    while number != 0:\n        number, i = divmod(number, 36)\n        base36.append(\"0123456789abcdefghijklmnopqrstuvwxyz\"[i])\n    return \"\".join(reversed(base36))\n\n\ndef is_valid_url(url):\n    parts = url_parse(url)\n    return parts.scheme in (\"http\", \"https\")\n\n\ndef get_hostname(url):\n    return url_parse(url).netloc\n\n\nclass Shortly:\n    def __init__(self, config):\n        self.redis = redis.Redis(config[\"redis_host\"], config[\"redis_port\"])\n        template_path = os.path.join(os.path.dirname(__file__), \"templates\")\n        self.jinja_env = Environment(\n            loader=FileSystemLoader(template_path), autoescape=True\n        )\n        self.jinja_env.filters[\"hostname\"] = get_hostname\n\n        self.url_map = Map(\n            [\n                Rule(\"/\", endpoint=\"new_url\"),\n                Rule(\"/<short_id>\", endpoint=\"follow_short_link\"),\n                Rule(\"/<short_id>+\", endpoint=\"short_link_details\"),\n            ]\n        )\n\n    def on_new_url(self, request):\n        error = None\n        url = \"\"\n        if request.method == \"POST\":\n            url = request.form[\"url\"]\n            if not is_valid_url(url):\n                error = \"Please enter a valid URL\"\n            else:\n                short_id = self.insert_url(url)\n                return redirect(f\"/{short_id}+\")\n        return self.render_template(\"new_url.html\", error=error, url=url)\n\n    def on_follow_short_link(self, request, short_id):\n        link_target = self.redis.get(f\"url-target:{short_id}\")\n        if link_target is None:\n            raise NotFound()\n        self.redis.incr(f\"click-count:{short_id}\")\n        return redirect(link_target)\n\n    def on_short_link_details(self, request, short_id):\n        link_target = self.redis.get(f\"url-target:{short_id}\")\n        if link_target is None:\n            raise NotFound()\n        click_count = int(self.redis.get(f\"click-count:{short_id}\") or 0)\n        return self.render_template(\n            \"short_link_details.html\",\n            link_target=link_target,\n            short_id=short_id,\n            click_count=click_count,\n        )\n\n    def error_404(self):\n        response = self.render_template(\"404.html\")\n        response.status_code = 404\n        return response\n\n    def insert_url(self, url):\n        short_id = self.redis.get(f\"reverse-url:{url}\")\n        if short_id is not None:\n            return short_id\n        url_num = self.redis.incr(\"last-url-id\")\n        short_id = base36_encode(url_num)\n        self.redis.set(f\"url-target:{short_id}\", url)\n        self.redis.set(f\"reverse-url:{url}\", short_id)\n        return short_id\n\n    def render_template(self, template_name, **context):\n        t = self.jinja_env.get_template(template_name)\n        return Response(t.render(context), mimetype=\"text/html\")\n\n    def dispatch_request(self, request):\n        adapter = self.url_map.bind_to_environ(request.environ)\n        try:\n            endpoint, values = adapter.match()\n            return getattr(self, f\"on_{endpoint}\")(request, **values)\n        except NotFound:\n            return self.error_404()\n        except HTTPException as e:\n            return e\n\n    def wsgi_app(self, environ, start_response):\n        request = Request(environ)\n        response = self.dispatch_request(request)\n        return response(environ, start_response)\n\n    def __call__(self, environ, start_response):\n        return self.wsgi_app(environ, start_response)\n\n\ndef create_app(redis_host=\"localhost\", redis_port=6379, with_static=True):\n    app = Shortly({\"redis_host\": redis_host, \"redis_port\": redis_port})\n    if with_static:\n        app.wsgi_app = SharedDataMiddleware(\n            app.wsgi_app, {\"/static\": os.path.join(os.path.dirname(__file__), \"static\")}\n        )\n    return app\n\n\nif __name__ == \"__main__\":\n    from werkzeug.serving import run_simple\n\n    app = create_app()\n    run_simple(\"127.0.0.1\", 5000, app, use_debugger=True, use_reloader=True)\n", "path": "examples/shortly/shortly.py"}], "after_files": [{"content": "\"\"\"A simple URL shortener using Werkzeug and redis.\"\"\"\nimport os\n\nimport redis\nfrom jinja2 import Environment\nfrom jinja2 import FileSystemLoader\nfrom werkzeug.exceptions import HTTPException\nfrom werkzeug.exceptions import NotFound\nfrom werkzeug.middleware.shared_data import SharedDataMiddleware\nfrom werkzeug.routing import Map\nfrom werkzeug.routing import Rule\nfrom werkzeug.urls import url_parse\nfrom werkzeug.utils import redirect\nfrom werkzeug.wrappers import Request\nfrom werkzeug.wrappers import Response\n\n\ndef base36_encode(number):\n    assert number >= 0, \"positive integer required\"\n    if number == 0:\n        return \"0\"\n    base36 = []\n    while number != 0:\n        number, i = divmod(number, 36)\n        base36.append(\"0123456789abcdefghijklmnopqrstuvwxyz\"[i])\n    return \"\".join(reversed(base36))\n\n\ndef is_valid_url(url):\n    parts = url_parse(url)\n    return parts.scheme in (\"http\", \"https\")\n\n\ndef get_hostname(url):\n    return url_parse(url).netloc\n\n\nclass Shortly:\n    def __init__(self, config):\n        self.redis = redis.Redis(\n            config[\"redis_host\"], config[\"redis_port\"], decode_responses=True\n        )\n        template_path = os.path.join(os.path.dirname(__file__), \"templates\")\n        self.jinja_env = Environment(\n            loader=FileSystemLoader(template_path), autoescape=True\n        )\n        self.jinja_env.filters[\"hostname\"] = get_hostname\n\n        self.url_map = Map(\n            [\n                Rule(\"/\", endpoint=\"new_url\"),\n                Rule(\"/<short_id>\", endpoint=\"follow_short_link\"),\n                Rule(\"/<short_id>+\", endpoint=\"short_link_details\"),\n            ]\n        )\n\n    def on_new_url(self, request):\n        error = None\n        url = \"\"\n        if request.method == \"POST\":\n            url = request.form[\"url\"]\n            if not is_valid_url(url):\n                error = \"Please enter a valid URL\"\n            else:\n                short_id = self.insert_url(url)\n                return redirect(f\"/{short_id}+\")\n        return self.render_template(\"new_url.html\", error=error, url=url)\n\n    def on_follow_short_link(self, request, short_id):\n        link_target = self.redis.get(f\"url-target:{short_id}\")\n        if link_target is None:\n            raise NotFound()\n        self.redis.incr(f\"click-count:{short_id}\")\n        return redirect(link_target)\n\n    def on_short_link_details(self, request, short_id):\n        link_target = self.redis.get(f\"url-target:{short_id}\")\n        if link_target is None:\n            raise NotFound()\n        click_count = int(self.redis.get(f\"click-count:{short_id}\") or 0)\n        return self.render_template(\n            \"short_link_details.html\",\n            link_target=link_target,\n            short_id=short_id,\n            click_count=click_count,\n        )\n\n    def error_404(self):\n        response = self.render_template(\"404.html\")\n        response.status_code = 404\n        return response\n\n    def insert_url(self, url):\n        short_id = self.redis.get(f\"reverse-url:{url}\")\n        if short_id is not None:\n            return short_id\n        url_num = self.redis.incr(\"last-url-id\")\n        short_id = base36_encode(url_num)\n        self.redis.set(f\"url-target:{short_id}\", url)\n        self.redis.set(f\"reverse-url:{url}\", short_id)\n        return short_id\n\n    def render_template(self, template_name, **context):\n        t = self.jinja_env.get_template(template_name)\n        return Response(t.render(context), mimetype=\"text/html\")\n\n    def dispatch_request(self, request):\n        adapter = self.url_map.bind_to_environ(request.environ)\n        try:\n            endpoint, values = adapter.match()\n            return getattr(self, f\"on_{endpoint}\")(request, **values)\n        except NotFound:\n            return self.error_404()\n        except HTTPException as e:\n            return e\n\n    def wsgi_app(self, environ, start_response):\n        request = Request(environ)\n        response = self.dispatch_request(request)\n        return response(environ, start_response)\n\n    def __call__(self, environ, start_response):\n        return self.wsgi_app(environ, start_response)\n\n\ndef create_app(redis_host=\"localhost\", redis_port=6379, with_static=True):\n    app = Shortly({\"redis_host\": redis_host, \"redis_port\": redis_port})\n    if with_static:\n        app.wsgi_app = SharedDataMiddleware(\n            app.wsgi_app, {\"/static\": os.path.join(os.path.dirname(__file__), \"static\")}\n        )\n    return app\n\n\nif __name__ == \"__main__\":\n    from werkzeug.serving import run_simple\n\n    app = create_app()\n    run_simple(\"127.0.0.1\", 5000, app, use_debugger=True, use_reloader=True)\n", "path": "examples/shortly/shortly.py"}]}