<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def request(self, method, data=None, nid=None, nid_key='nid', api_type="logic", return_response=False):
 """Get data from arbitrary Piazza API endpoint `method` in network `nid` :type method: str :param method: An internal Piazza API method name like `content.get` or `network.get_users` :type data: dict :param data: Key-value data to pass to Piazza in the request :type nid: str :param nid: This is the ID of the network to which the request should be made. This is optional and only to override the existing `network_id` entered when creating the class :type nid_key: str :param nid_key: Name expected by Piazza for `nid` when making request. (Usually and by default "nid", but sometimes "id" is expected) :returns: Python object containing returned data :type return_response: bool :param return_response: If set, returns whole :class:`requests.Response` object rather than just the response body """

        self._check_authenticated()

        nid = nid if nid else self._nid
        if data is None:
            data = {}

        headers = {}
        if "session_id" in self.session.cookies:
            headers["CSRF-Token"] = self.session.cookies["session_id"]

        # Adding a nonce to the request
        endpoint = self.base_api_urls[api_type]
        if api_type == "logic":
            endpoint += "?method={}&aid={}".format(
                method,
                _piazza_nonce()
            )

        response = self.session.post(
            endpoint,
            data=json.dumps({
                "method": method,
                "params": dict({nid_key: nid}, **data)
            }),
            headers=headers
        )
        return response if return_response else response.json()