How to use the rpcq._base.to_json function in rpcq

To help you get started, we’ve selected a few rpcq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rigetti / pyquil / pyquil / api / _compiler.py View on Github external
If the request succeeds (per HTTP response code), the body of the response is parsed into
        an RPCQ Message.

        If the request fails, the response body should be a JSON object with a ``message`` field
        indicating the cause of the failure. If present, that message is delivered to the user.

        :param payload: The rpcq message body.
        :param rpc_timeout: The number of seconds to wait to read data back from the service
            after connection.
            @see https://requests.readthedocs.io/en/master/user/advanced/#timeouts
        """
        url = urljoin(self.endpoint, method)

        if payload:
            body = to_json(payload)
        else:
            body = None

        response = self.session.post(url, json=body, timeout=(1, rpc_timeout))

        try:
            response.raise_for_status()
        except RequestException as e:
            message = f"QPU Compiler {method} failed: "

            try:
                contents = response.json()
            except Exception:
                contents = None

            if contents and contents.get("message"):