We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Support body param in RequestMethods.request
Easiest way to do this is by avoiding defining a body kw when no fields are given, then if both are given it will naturally raise a "passed twice" error.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `urllib3/request.py`
Content:
```
1 try:
2     from urllib.parse import urlencode
3 except ImportError:
4     from urllib import urlencode
5 
6 from .filepost import encode_multipart_formdata
7 
8 
9 __all__ = ['RequestMethods']
10 
11 
12 class RequestMethods(object):
13     """
14     Convenience mixin for classes who implement a :meth:`urlopen` method, such
15     as :class:`~urllib3.connectionpool.HTTPConnectionPool` and
16     :class:`~urllib3.poolmanager.PoolManager`.
17 
18     Provides behavior for making common types of HTTP request methods and
19     decides which type of request field encoding to use.
20 
21     Specifically,
22 
23     :meth:`.request_encode_url` is for sending requests whose fields are
24     encoded in the URL (such as GET, HEAD, DELETE).
25 
26     :meth:`.request_encode_body` is for sending requests whose fields are
27     encoded in the *body* of the request using multipart or www-form-urlencoded
28     (such as for POST, PUT, PATCH).
29 
30     :meth:`.request` is for making any kind of request, it will look up the
31     appropriate encoding format and use one of the above two methods to make
32     the request.
33 
34     Initializer parameters:
35 
36     :param headers:
37         Headers to include with all requests, unless other headers are given
38         explicitly.
39     """
40 
41     _encode_url_methods = set(['DELETE', 'GET', 'HEAD', 'OPTIONS'])
42 
43     def __init__(self, headers=None):
44         self.headers = headers or {}
45 
46     def urlopen(self, method, url, body=None, headers=None,
47                 encode_multipart=True, multipart_boundary=None,
48                 **kw):  # Abstract
49         raise NotImplemented("Classes extending RequestMethods must implement "
50                              "their own ``urlopen`` method.")
51 
52     def request(self, method, url, fields=None, headers=None, **urlopen_kw):
53         """
54         Make a request using :meth:`urlopen` with the appropriate encoding of
55         ``fields`` based on the ``method`` used.
56 
57         This is a convenience method that requires the least amount of manual
58         effort. It can be used in most situations, while still having the
59         option to drop down to more specific methods when necessary, such as
60         :meth:`request_encode_url`, :meth:`request_encode_body`,
61         or even the lowest level :meth:`urlopen`.
62         """
63         method = method.upper()
64 
65         if method in self._encode_url_methods:
66             return self.request_encode_url(method, url, fields=fields,
67                                            headers=headers,
68                                            **urlopen_kw)
69         else:
70             return self.request_encode_body(method, url, fields=fields,
71                                             headers=headers,
72                                             **urlopen_kw)
73 
74     def request_encode_url(self, method, url, fields=None, **urlopen_kw):
75         """
76         Make a request using :meth:`urlopen` with the ``fields`` encoded in
77         the url. This is useful for request methods like GET, HEAD, DELETE, etc.
78         """
79         if fields:
80             url += '?' + urlencode(fields)
81         return self.urlopen(method, url, **urlopen_kw)
82 
83     def request_encode_body(self, method, url, fields=None, headers=None,
84                             encode_multipart=True, multipart_boundary=None,
85                             **urlopen_kw):
86         """
87         Make a request using :meth:`urlopen` with the ``fields`` encoded in
88         the body. This is useful for request methods like POST, PUT, PATCH, etc.
89 
90         When ``encode_multipart=True`` (default), then
91         :meth:`urllib3.filepost.encode_multipart_formdata` is used to encode
92         the payload with the appropriate content type. Otherwise
93         :meth:`urllib.urlencode` is used with the
94         'application/x-www-form-urlencoded' content type.
95 
96         Multipart encoding must be used when posting files, and it's reasonably
97         safe to use it in other times too. However, it may break request
98         signing, such as with OAuth.
99 
100         Supports an optional ``fields`` parameter of key/value strings AND
101         key/filetuple. A filetuple is a (filename, data, MIME type) tuple where
102         the MIME type is optional. For example::
103 
104             fields = {
105                 'foo': 'bar',
106                 'fakefile': ('foofile.txt', 'contents of foofile'),
107                 'realfile': ('barfile.txt', open('realfile').read()),
108                 'typedfile': ('bazfile.bin', open('bazfile').read(),
109                               'image/jpeg'),
110                 'nonamefile': 'contents of nonamefile field',
111             }
112 
113         When uploading a file, providing a filename (the first parameter of the
114         tuple) is optional but recommended to best mimick behavior of browsers.
115 
116         Note that if ``headers`` are supplied, the 'Content-Type' header will
117         be overwritten because it depends on the dynamic random boundary string
118         which is used to compose the body of the request. The random boundary
119         string can be explicitly set with the ``multipart_boundary`` parameter.
120         """
121         if encode_multipart:
122             body, content_type = encode_multipart_formdata(
123                 fields or {}, boundary=multipart_boundary)
124         else:
125             body, content_type = (urlencode(fields or {}),
126                                   'application/x-www-form-urlencoded')
127 
128         if headers is None:
129             headers = self.headers
130 
131         headers_ = {'Content-Type': content_type}
132         headers_.update(headers)
133 
134         return self.urlopen(method, url, body=body, headers=headers_,
135                             **urlopen_kw)
136
```
--- 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/urllib3/request.py b/urllib3/request.py
--- a/urllib3/request.py
+++ b/urllib3/request.py
@@ -118,18 +118,24 @@
         which is used to compose the body of the request. The random boundary
         string can be explicitly set with the ``multipart_boundary`` parameter.
         """
-        if encode_multipart:
-            body, content_type = encode_multipart_formdata(
-                fields or {}, boundary=multipart_boundary)
-        else:
-            body, content_type = (urlencode(fields or {}),
-                                  'application/x-www-form-urlencoded')
-
         if headers is None:
             headers = self.headers
 
-        headers_ = {'Content-Type': content_type}
-        headers_.update(headers)
+        extra_kw = {'headers': {}}
+
+        if fields:
+            if 'body' in urlopen_kw:
+                raise TypeError('request got values for both \'fields\' and \'body\', can only specify one.')
+
+            if encode_multipart:
+                body, content_type = encode_multipart_formdata(fields, boundary=multipart_boundary)
+            else:
+                body, content_type = urlencode(fields), 'application/x-www-form-urlencoded'
+
+            extra_kw['body'] = body
+            extra_kw['headers'] = {'Content-Type': content_type}
+
+        extra_kw['headers'].update(headers)
+        extra_kw.update(urlopen_kw)
 
-        return self.urlopen(method, url, body=body, headers=headers_,
-                            **urlopen_kw)
+        return self.urlopen(method, url, **extra_kw)

{"golden_diff": "diff --git a/urllib3/request.py b/urllib3/request.py\n--- a/urllib3/request.py\n+++ b/urllib3/request.py\n@@ -118,18 +118,24 @@\n         which is used to compose the body of the request. The random boundary\n         string can be explicitly set with the ``multipart_boundary`` parameter.\n         \"\"\"\n-        if encode_multipart:\n-            body, content_type = encode_multipart_formdata(\n-                fields or {}, boundary=multipart_boundary)\n-        else:\n-            body, content_type = (urlencode(fields or {}),\n-                                  'application/x-www-form-urlencoded')\n-\n         if headers is None:\n             headers = self.headers\n \n-        headers_ = {'Content-Type': content_type}\n-        headers_.update(headers)\n+        extra_kw = {'headers': {}}\n+\n+        if fields:\n+            if 'body' in urlopen_kw:\n+                raise TypeError('request got values for both \\'fields\\' and \\'body\\', can only specify one.')\n+\n+            if encode_multipart:\n+                body, content_type = encode_multipart_formdata(fields, boundary=multipart_boundary)\n+            else:\n+                body, content_type = urlencode(fields), 'application/x-www-form-urlencoded'\n+\n+            extra_kw['body'] = body\n+            extra_kw['headers'] = {'Content-Type': content_type}\n+\n+        extra_kw['headers'].update(headers)\n+        extra_kw.update(urlopen_kw)\n \n-        return self.urlopen(method, url, body=body, headers=headers_,\n-                            **urlopen_kw)\n+        return self.urlopen(method, url, **extra_kw)\n", "issue": "Support body param in RequestMethods.request\nEasiest way to do this is by avoiding defining a body kw when no fields are given, then if both are given it will naturally raise a \"passed twice\" error.\n\n", "before_files": [{"content": "try:\n    from urllib.parse import urlencode\nexcept ImportError:\n    from urllib import urlencode\n\nfrom .filepost import encode_multipart_formdata\n\n\n__all__ = ['RequestMethods']\n\n\nclass RequestMethods(object):\n    \"\"\"\n    Convenience mixin for classes who implement a :meth:`urlopen` method, such\n    as :class:`~urllib3.connectionpool.HTTPConnectionPool` and\n    :class:`~urllib3.poolmanager.PoolManager`.\n\n    Provides behavior for making common types of HTTP request methods and\n    decides which type of request field encoding to use.\n\n    Specifically,\n\n    :meth:`.request_encode_url` is for sending requests whose fields are\n    encoded in the URL (such as GET, HEAD, DELETE).\n\n    :meth:`.request_encode_body` is for sending requests whose fields are\n    encoded in the *body* of the request using multipart or www-form-urlencoded\n    (such as for POST, PUT, PATCH).\n\n    :meth:`.request` is for making any kind of request, it will look up the\n    appropriate encoding format and use one of the above two methods to make\n    the request.\n\n    Initializer parameters:\n\n    :param headers:\n        Headers to include with all requests, unless other headers are given\n        explicitly.\n    \"\"\"\n\n    _encode_url_methods = set(['DELETE', 'GET', 'HEAD', 'OPTIONS'])\n\n    def __init__(self, headers=None):\n        self.headers = headers or {}\n\n    def urlopen(self, method, url, body=None, headers=None,\n                encode_multipart=True, multipart_boundary=None,\n                **kw):  # Abstract\n        raise NotImplemented(\"Classes extending RequestMethods must implement \"\n                             \"their own ``urlopen`` method.\")\n\n    def request(self, method, url, fields=None, headers=None, **urlopen_kw):\n        \"\"\"\n        Make a request using :meth:`urlopen` with the appropriate encoding of\n        ``fields`` based on the ``method`` used.\n\n        This is a convenience method that requires the least amount of manual\n        effort. It can be used in most situations, while still having the\n        option to drop down to more specific methods when necessary, such as\n        :meth:`request_encode_url`, :meth:`request_encode_body`,\n        or even the lowest level :meth:`urlopen`.\n        \"\"\"\n        method = method.upper()\n\n        if method in self._encode_url_methods:\n            return self.request_encode_url(method, url, fields=fields,\n                                           headers=headers,\n                                           **urlopen_kw)\n        else:\n            return self.request_encode_body(method, url, fields=fields,\n                                            headers=headers,\n                                            **urlopen_kw)\n\n    def request_encode_url(self, method, url, fields=None, **urlopen_kw):\n        \"\"\"\n        Make a request using :meth:`urlopen` with the ``fields`` encoded in\n        the url. This is useful for request methods like GET, HEAD, DELETE, etc.\n        \"\"\"\n        if fields:\n            url += '?' + urlencode(fields)\n        return self.urlopen(method, url, **urlopen_kw)\n\n    def request_encode_body(self, method, url, fields=None, headers=None,\n                            encode_multipart=True, multipart_boundary=None,\n                            **urlopen_kw):\n        \"\"\"\n        Make a request using :meth:`urlopen` with the ``fields`` encoded in\n        the body. This is useful for request methods like POST, PUT, PATCH, etc.\n\n        When ``encode_multipart=True`` (default), then\n        :meth:`urllib3.filepost.encode_multipart_formdata` is used to encode\n        the payload with the appropriate content type. Otherwise\n        :meth:`urllib.urlencode` is used with the\n        'application/x-www-form-urlencoded' content type.\n\n        Multipart encoding must be used when posting files, and it's reasonably\n        safe to use it in other times too. However, it may break request\n        signing, such as with OAuth.\n\n        Supports an optional ``fields`` parameter of key/value strings AND\n        key/filetuple. A filetuple is a (filename, data, MIME type) tuple where\n        the MIME type is optional. For example::\n\n            fields = {\n                'foo': 'bar',\n                'fakefile': ('foofile.txt', 'contents of foofile'),\n                'realfile': ('barfile.txt', open('realfile').read()),\n                'typedfile': ('bazfile.bin', open('bazfile').read(),\n                              'image/jpeg'),\n                'nonamefile': 'contents of nonamefile field',\n            }\n\n        When uploading a file, providing a filename (the first parameter of the\n        tuple) is optional but recommended to best mimick behavior of browsers.\n\n        Note that if ``headers`` are supplied, the 'Content-Type' header will\n        be overwritten because it depends on the dynamic random boundary string\n        which is used to compose the body of the request. The random boundary\n        string can be explicitly set with the ``multipart_boundary`` parameter.\n        \"\"\"\n        if encode_multipart:\n            body, content_type = encode_multipart_formdata(\n                fields or {}, boundary=multipart_boundary)\n        else:\n            body, content_type = (urlencode(fields or {}),\n                                  'application/x-www-form-urlencoded')\n\n        if headers is None:\n            headers = self.headers\n\n        headers_ = {'Content-Type': content_type}\n        headers_.update(headers)\n\n        return self.urlopen(method, url, body=body, headers=headers_,\n                            **urlopen_kw)\n", "path": "urllib3/request.py"}], "after_files": [{"content": "try:\n    from urllib.parse import urlencode\nexcept ImportError:\n    from urllib import urlencode\n\nfrom .filepost import encode_multipart_formdata\n\n\n__all__ = ['RequestMethods']\n\n\nclass RequestMethods(object):\n    \"\"\"\n    Convenience mixin for classes who implement a :meth:`urlopen` method, such\n    as :class:`~urllib3.connectionpool.HTTPConnectionPool` and\n    :class:`~urllib3.poolmanager.PoolManager`.\n\n    Provides behavior for making common types of HTTP request methods and\n    decides which type of request field encoding to use.\n\n    Specifically,\n\n    :meth:`.request_encode_url` is for sending requests whose fields are\n    encoded in the URL (such as GET, HEAD, DELETE).\n\n    :meth:`.request_encode_body` is for sending requests whose fields are\n    encoded in the *body* of the request using multipart or www-form-urlencoded\n    (such as for POST, PUT, PATCH).\n\n    :meth:`.request` is for making any kind of request, it will look up the\n    appropriate encoding format and use one of the above two methods to make\n    the request.\n\n    Initializer parameters:\n\n    :param headers:\n        Headers to include with all requests, unless other headers are given\n        explicitly.\n    \"\"\"\n\n    _encode_url_methods = set(['DELETE', 'GET', 'HEAD', 'OPTIONS'])\n\n    def __init__(self, headers=None):\n        self.headers = headers or {}\n\n    def urlopen(self, method, url, body=None, headers=None,\n                encode_multipart=True, multipart_boundary=None,\n                **kw):  # Abstract\n        raise NotImplemented(\"Classes extending RequestMethods must implement \"\n                             \"their own ``urlopen`` method.\")\n\n    def request(self, method, url, fields=None, headers=None, **urlopen_kw):\n        \"\"\"\n        Make a request using :meth:`urlopen` with the appropriate encoding of\n        ``fields`` based on the ``method`` used.\n\n        This is a convenience method that requires the least amount of manual\n        effort. It can be used in most situations, while still having the\n        option to drop down to more specific methods when necessary, such as\n        :meth:`request_encode_url`, :meth:`request_encode_body`,\n        or even the lowest level :meth:`urlopen`.\n        \"\"\"\n        method = method.upper()\n\n        if method in self._encode_url_methods:\n            return self.request_encode_url(method, url, fields=fields,\n                                           headers=headers,\n                                           **urlopen_kw)\n        else:\n            return self.request_encode_body(method, url, fields=fields,\n                                            headers=headers,\n                                            **urlopen_kw)\n\n    def request_encode_url(self, method, url, fields=None, **urlopen_kw):\n        \"\"\"\n        Make a request using :meth:`urlopen` with the ``fields`` encoded in\n        the url. This is useful for request methods like GET, HEAD, DELETE, etc.\n        \"\"\"\n        if fields:\n            url += '?' + urlencode(fields)\n        return self.urlopen(method, url, **urlopen_kw)\n\n    def request_encode_body(self, method, url, fields=None, headers=None,\n                            encode_multipart=True, multipart_boundary=None,\n                            **urlopen_kw):\n        \"\"\"\n        Make a request using :meth:`urlopen` with the ``fields`` encoded in\n        the body. This is useful for request methods like POST, PUT, PATCH, etc.\n\n        When ``encode_multipart=True`` (default), then\n        :meth:`urllib3.filepost.encode_multipart_formdata` is used to encode\n        the payload with the appropriate content type. Otherwise\n        :meth:`urllib.urlencode` is used with the\n        'application/x-www-form-urlencoded' content type.\n\n        Multipart encoding must be used when posting files, and it's reasonably\n        safe to use it in other times too. However, it may break request\n        signing, such as with OAuth.\n\n        Supports an optional ``fields`` parameter of key/value strings AND\n        key/filetuple. A filetuple is a (filename, data, MIME type) tuple where\n        the MIME type is optional. For example::\n\n            fields = {\n                'foo': 'bar',\n                'fakefile': ('foofile.txt', 'contents of foofile'),\n                'realfile': ('barfile.txt', open('realfile').read()),\n                'typedfile': ('bazfile.bin', open('bazfile').read(),\n                              'image/jpeg'),\n                'nonamefile': 'contents of nonamefile field',\n            }\n\n        When uploading a file, providing a filename (the first parameter of the\n        tuple) is optional but recommended to best mimick behavior of browsers.\n\n        Note that if ``headers`` are supplied, the 'Content-Type' header will\n        be overwritten because it depends on the dynamic random boundary string\n        which is used to compose the body of the request. The random boundary\n        string can be explicitly set with the ``multipart_boundary`` parameter.\n        \"\"\"\n        if headers is None:\n            headers = self.headers\n\n        extra_kw = {'headers': {}}\n\n        if fields:\n            if 'body' in urlopen_kw:\n                raise TypeError('request got values for both \\'fields\\' and \\'body\\', can only specify one.')\n\n            if encode_multipart:\n                body, content_type = encode_multipart_formdata(fields, boundary=multipart_boundary)\n            else:\n                body, content_type = urlencode(fields), 'application/x-www-form-urlencoded'\n\n            extra_kw['body'] = body\n            extra_kw['headers'] = {'Content-Type': content_type}\n\n        extra_kw['headers'].update(headers)\n        extra_kw.update(urlopen_kw)\n\n        return self.urlopen(method, url, **extra_kw)\n", "path": "urllib3/request.py"}]}