# Buggy code
def request(
    self,
    method: str,
    path: str,
    params: Optional[Union[str, Dict[str, str]]] = None,
    data: Optional[Union[Dict[str, Union[str, Any]], bytes, IO, str]] = None,
    files: Optional[Dict[str, IO]] = None,
    json=None,
) -> Any:
    """Return the parsed JSON data returned from a request to URL.

    :param method: The HTTP method (e.g., GET, POST, PUT, DELETE).
    :param path: The path to fetch.
    :param params: The query parameters to add to the request (default:
        None).
    :param data: Dictionary, bytes, or file-like object to send in the body
        of the request (default: None).
    :param files: Dictionary, filename to file (like) object mapping
        (default: None).
    :param json: JSON-serializable object to send in the body
        of the request with a Content-Type header of application/json
        (default: None). If ``json`` is provided, ``data`` should not be.

    """
    if data and json:
        raise ClientException("At most one of `data` and `json` is supported.")
    try:
        return self._core.request(
            method,
            path,
            data=data,
            files=files,
            params=params,
            timeout=self.config.timeout,
            json=json,
        )
    except BadRequest as exception:
        try:
            data = exception.response.json()
        except ValueError:
            # TODO: Remove this exception after 2020-12-31 if no one has
            # filed a bug against it.
            raise Exception(
                "Unexpected BadRequest without json body. Please file a "
                "bug at https://github.com/praw-dev/praw/issues"
            ) from exception
        if "fields" in data:
            assert len(data["fields"]) == 1
            field = data["fields"][0]
        else:
            field = None
        raise RedditAPIException(
            [data["reason"], data["explanation"], field]
        ) from exception


# Traceback (KeyError)
---------------------------------------------------------------------------
BadRequest                                Traceback (most recent call last)
~/PycharmProjects/praw/praw/reddit.py in request(self, method, path, params, data, files)
731                 params=params,
--> 732                 timeout=self.config.timeout,
733             )

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/prawcore/sessions.py in request(self, method, path, data, files, json, params, timeout)
335             timeout=timeout,
--> 336             url=url,
337         )

~/.virtualenvs/praw/venv/lib/python3.7/site-packages/prawcore/sessions.py in _request_with_retries(self, data, files, json, method, params, timeout, url, retry_strategy_state)
264         elif response.status_code in self.STATUS_EXCEPTIONS:
--> 265             raise self.STATUS_EXCEPTIONS[response.status_code](response)
266         elif response.status_code == codes["no_content"]:

BadRequest: received 400 HTTP response

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-5-e7b204c10e9b> in <module>
----> 1 r = reddit.post("/api/validate_submission_field", data={"sr": "AskReddit", "field": "link", "kind": "link", "title": "l", "text": "lol",  "show_error_list": True, })

~/PycharmProjects/praw/praw/reddit.py in post(self, path, data, files, params)
635                 method="POST",
636                 params=params,
--> 637                 path=path,
638             )
639         except RedditAPIException as exception:

~/PycharmProjects/praw/praw/reddit.py in _objectify_request(self, data, files, method, params, path)
572         return self._objector.objectify(
573             self.request(
--> 574                 data=data, files=files, method=method, params=params, path=path
575             )
576         )

~/PycharmProjects/praw/praw/reddit.py in request(self, method, path, params, data, files)
748                 field = None
749             raise RedditAPIException(
--> 750                 [data["reason"], data["explanation"], field]
751             ) from exception
752

KeyError: 'reason'

# Fixed code
def request(
    self,
    method: str,
    path: str,
    params: Optional[Union[str, Dict[str, str]]] = None,
    data: Optional[Union[Dict[str, Union[str, Any]], bytes, IO, str]] = None,
    files: Optional[Dict[str, IO]] = None,
    json=None,
) -> Any:
    """Return the parsed JSON data returned from a request to URL.

    :param method: The HTTP method (e.g., GET, POST, PUT, DELETE).
    :param path: The path to fetch.
    :param params: The query parameters to add to the request (default:
        None).
    :param data: Dictionary, bytes, or file-like object to send in the body
        of the request (default: None).
    :param files: Dictionary, filename to file (like) object mapping
        (default: None).
    :param json: JSON-serializable object to send in the body
        of the request with a Content-Type header of application/json
        (default: None). If ``json`` is provided, ``data`` should not be.

    """
    if data and json:
        raise ClientException("At most one of `data` and `json` is supported.")
    try:
        return self._core.request(
            method,
            path,
            data=data,
            files=files,
            params=params,
            timeout=self.config.timeout,
            json=json,
        )
    except BadRequest as exception:
        try:
            data = exception.response.json()
        except ValueError:
            # TODO: Remove this exception after 2020-12-31 if no one has
            # filed a bug against it.
            raise Exception(
                "Unexpected BadRequest without json body. Please file a "
                "bug at https://github.com/praw-dev/praw/issues"
            ) from exception
        if set(data) == {"error", "message"}:
            raise
        if "fields" in data:
            assert len(data["fields"]) == 1
            field = data["fields"][0]
        else:
            field = None
        raise RedditAPIException(
            [data["reason"], data["explanation"], field]
        ) from exception