Skip to content

Commit

Permalink
Add accept header
Browse files Browse the repository at this point in the history
  • Loading branch information
kt474 committed Dec 17, 2024
1 parent 3bae07c commit 9e56dac
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions qiskit_ibm_runtime/api/rest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class RestAdapterBase:

_HEADER_JSON_CONTENT = {"Content-Type": "application/json"}

_HEADER_JSON_ACCEPT = {"Accept": "application/json"}

def __init__(self, session: RetrySession, prefix_url: str = "") -> None:
"""RestAdapterBase constructor.
Expand Down
4 changes: 4 additions & 0 deletions qiskit_ibm_runtime/api/rest/cloud_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def configuration(self) -> Dict[str, Any]:
JSON response of backend configuration.
"""
url = self.get_url("configuration")
self.session.headers.update(self._HEADER_JSON_ACCEPT)
return self.session.get(url).json()

def properties(self, datetime: Optional[python_datetime] = None) -> Dict[str, Any]:
Expand All @@ -61,6 +62,7 @@ def properties(self, datetime: Optional[python_datetime] = None) -> Dict[str, An
if datetime:
params["updated_before"] = datetime.isoformat()

self.session.headers.update(self._HEADER_JSON_ACCEPT)
response = self.session.get(url, params=params).json()
# Adjust name of the backend.
if response:
Expand All @@ -74,6 +76,7 @@ def pulse_defaults(self) -> Dict[str, Any]:
JSON response of pulse defaults.
"""
url = self.get_url("pulse_defaults")
self.session.headers.update(self._HEADER_JSON_ACCEPT)
return self.session.get(url).json()

def status(self) -> Dict[str, Any]:
Expand All @@ -83,6 +86,7 @@ def status(self) -> Dict[str, Any]:
JSON response of backend status.
"""
url = self.get_url("status")
self.session.headers.update(self._HEADER_JSON_ACCEPT)
response = self.session.get(url).json()
# Adjust fields according to the specs (BackendStatus).
ret = {
Expand Down
3 changes: 3 additions & 0 deletions qiskit_ibm_runtime/api/rest/program_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def get(self, exclude_params: bool = None) -> Dict:
payload = {}
if exclude_params:
payload["exclude_params"] = "true"

self.session.headers.update(self._HEADER_JSON_ACCEPT)
return self.session.get(self.get_url("self"), params=payload).json(cls=RuntimeDecoder)

def delete(self) -> None:
Expand Down Expand Up @@ -98,6 +100,7 @@ def metadata(self) -> Dict:
Returns:
Job Metadata.
"""
self.session.headers.update(self._HEADER_JSON_ACCEPT)
return self.session.get(self.get_url("metrics")).json()

def update_tags(self, tags: list) -> Response:
Expand Down
5 changes: 5 additions & 0 deletions qiskit_ibm_runtime/api/rest/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def hubs(self) -> List[Dict[str, Any]]:
JSON response.
"""
url = self.get_url("hubs")

self.session.headers.update(self._HEADER_JSON_ACCEPT)
return self.session.get(url).json()

def version(self) -> Dict[str, Union[str, bool]]:
Expand All @@ -69,6 +71,7 @@ def version(self) -> Dict[str, Union[str, bool]]:
* ``api-*`` (str): The versions of each individual API component
"""
url = self.get_url("version")
self.session.headers.update(self._HEADER_JSON_ACCEPT)
response = self.session.get(url)

try:
Expand Down Expand Up @@ -99,6 +102,8 @@ def user_info(self) -> Dict[str, Any]:
JSON response of user information.
"""
url = self.get_url("user_info")

self.session.headers.update(self._HEADER_JSON_ACCEPT)
response = self.session.get(url).json()

return response
3 changes: 3 additions & 0 deletions qiskit_ibm_runtime/api/rest/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def jobs_get(
payload["sort"] = "ASC"
if all([hub, group, project]):
payload["provider"] = f"{hub}/{group}/{project}"
self.session.headers.update(self._HEADER_JSON_ACCEPT)
return self.session.get(url, params=payload).json()

def backend(self, backend_name: str) -> CloudBackend:
Expand Down Expand Up @@ -227,6 +228,7 @@ def backends(
params = {}
if hgp:
params["provider"] = hgp
self.session.headers.update(self._HEADER_JSON_ACCEPT)
return self.session.get(url, params=params, timeout=timeout).json()

def usage(self) -> Dict[str, Any]:
Expand All @@ -236,4 +238,5 @@ def usage(self) -> Dict[str, Any]:
JSON response.
"""
url = self.get_url("usage")
self.session.headers.update(self._HEADER_JSON_ACCEPT)
return self.session.get(url).json()
2 changes: 2 additions & 0 deletions qiskit_ibm_runtime/api/rest/runtime_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ def close(self) -> None:

def details(self) -> Dict[str, Any]:
"""Return the details of this session."""

self.session.headers.update(self._HEADER_JSON_ACCEPT)
return self.session.get(self.get_url("self")).json()

0 comments on commit 9e56dac

Please sign in to comment.