-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
Hi RCSB API team, thank you very much for your work! May I ask for your help? I tried to run a simple Data API example
from rcsbapi.data import DataQuery as Query
query = Query(
input_type="entries",
input_ids=["4HHB"],
return_data_list=["exptl.method"]
)
result_dict = query.exec()
print(result_dict)and got the following error
---------------------------------------------------------------------------
AsyncLibraryNotFoundError Traceback (most recent call last)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py:228](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py#line=227), in AsyncConnectionPool.handle_async_request(self, request)
225 with self._optional_thread_lock:
226 # Assign incoming requests to available connections,
227 # closing or creating new connections as required.
--> 228 closing = self._assign_requests_to_connections()
229 await self._close_connections(closing)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py:328](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py#line=327), in AsyncConnectionPool._assign_requests_to_connections(self)
327 self._connections.append(connection)
--> 328 pool_request.assign_to_connection(connection)
329 elif idle_connections:
330 # log: "closing idle connection"
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py:25](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py#line=24), in AsyncPoolRequest.assign_to_connection(self, connection)
24 self.connection = connection
---> 25 self._connection_acquired.set()
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py:130](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py#line=129), in AsyncEvent.set(self)
129 if not self._backend:
--> 130 self.setup()
132 if self._backend == "trio":
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py:122](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py#line=121), in AsyncEvent.setup(self)
118 """
119 Detect if we're running under 'asyncio' or 'trio' and create
120 a lock with the correct implementation.
121 """
--> 122 self._backend = current_async_library()
123 if self._backend == "trio":
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py:30](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py#line=29), in current_async_library()
29 else:
---> 30 environment = sniffio.current_async_library()
32 if environment not in ("asyncio", "trio"): # pragma: nocover
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/sniffio/_impl.py:93](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/sniffio/_impl.py#line=92), in current_async_library()
91 return 'curio'
---> 93 raise AsyncLibraryNotFoundError(
94 "unknown async library, or not in async context"
95 )
AsyncLibraryNotFoundError: unknown async library, or not in async context
During handling of the above exception, another exception occurred:
AsyncLibraryNotFoundError Traceback (most recent call last)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/rcsbapi/data/data_query.py:234](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/rcsbapi/data/data_query.py#line=233), in DataQuery._async_exec(self, batch_size, progress_bar, max_concurrency, max_retries, retry_backoff)
233 else:
--> 234 results = await asyncio.gather(*tasks)
236 # Merge results
File [~/miniforge3/envs/endgroups/lib/python3.14/asyncio/tasks.py:362](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/asyncio/tasks.py#line=361), in Task.__wakeup(self, future)
361 try:
--> 362 future.result()
363 except BaseException as exc:
364 # This may also be a cancellation.
File [~/miniforge3/envs/endgroups/lib/python3.14/asyncio/tasks.py:289](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/asyncio/tasks.py#line=288), in Task.__step_run_and_handle_result(***failed resolving arguments***)
286 if exc is None:
287 # We use the `send` method directly, because coroutines
288 # don't have `__iter__` and `__next__` methods.
--> 289 result = coro.send(None)
290 else:
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/rcsbapi/data/data_query.py:263](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/rcsbapi/data/data_query.py#line=262), in DataQuery._submit_request(self, client, query_body, semaphores, max_retries, retry_backoff)
261 #
262 # Now perform the actual request
--> 263 response = await client.post(
264 url=const.DATA_API_ENDPOINT,
265 headers={"Content-Type": "application[/json](http://localhost:8081/json)", "User-Agent": const.USER_AGENT},
266 json={"query": query_body}
267 )
268 response.raise_for_status() # Raise an error for bad responses
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py:1859](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py#line=1858), in AsyncClient.post(self, url, content, data, files, json, params, headers, cookies, auth, follow_redirects, timeout, extensions)
1854 """
1855 Send a `POST` request.
1856
1857 **Parameters**: See `httpx.request`.
1858 """
-> 1859 return await self.request(
1860 "POST",
1861 url,
1862 content=content,
1863 data=data,
1864 files=files,
1865 json=json,
1866 params=params,
1867 headers=headers,
1868 cookies=cookies,
1869 auth=auth,
1870 follow_redirects=follow_redirects,
1871 timeout=timeout,
1872 extensions=extensions,
1873 )
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py:1540](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py#line=1539), in AsyncClient.request(self, method, url, content, data, files, json, params, headers, cookies, auth, follow_redirects, timeout, extensions)
1527 request = self.build_request(
1528 method=method,
1529 url=url,
(...) 1538 extensions=extensions,
1539 )
-> 1540 return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py:1629](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py#line=1628), in AsyncClient.send(self, request, stream, auth, follow_redirects)
1627 auth = self._build_request_auth(request, auth)
-> 1629 response = await self._send_handling_auth(
1630 request,
1631 auth=auth,
1632 follow_redirects=follow_redirects,
1633 history=[],
1634 )
1635 try:
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py:1657](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py#line=1656), in AsyncClient._send_handling_auth(self, request, auth, follow_redirects, history)
1656 while True:
-> 1657 response = await self._send_handling_redirects(
1658 request,
1659 follow_redirects=follow_redirects,
1660 history=history,
1661 )
1662 try:
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py:1694](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py#line=1693), in AsyncClient._send_handling_redirects(self, request, follow_redirects, history)
1692 await hook(request)
-> 1694 response = await self._send_single_request(request)
1695 try:
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py:1730](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py#line=1729), in AsyncClient._send_single_request(self, request)
1729 with request_context(request=request):
-> 1730 response = await transport.handle_async_request(request)
1732 assert isinstance(response.stream, AsyncByteStream)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_transports/default.py:394](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_transports/default.py#line=393), in AsyncHTTPTransport.handle_async_request(self, request)
393 with map_httpcore_exceptions():
--> 394 resp = await self._pool.handle_async_request(req)
396 assert isinstance(resp.stream, typing.AsyncIterable)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py:255](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py#line=254), in AsyncConnectionPool.handle_async_request(self, request)
253 closing = self._assign_requests_to_connections()
--> 255 await self._close_connections(closing)
256 raise exc from None
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py:343](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py#line=342), in AsyncConnectionPool._close_connections(self, closing)
341 async def _close_connections(self, closing: list[AsyncConnectionInterface]) -> None:
342 # Close connections which have been removed from the pool.
--> 343 with AsyncShieldCancellation():
344 for connection in closing:
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py:203](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py#line=202), in AsyncShieldCancellation.__init__(self)
199 """
200 Detect if we're running under 'asyncio' or 'trio' and create
201 a shielded scope with the correct implementation.
202 """
--> 203 self._backend = current_async_library()
205 if self._backend == "trio":
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py:30](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py#line=29), in current_async_library()
29 else:
---> 30 environment = sniffio.current_async_library()
32 if environment not in ("asyncio", "trio"): # pragma: nocover
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/sniffio/_impl.py:93](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/sniffio/_impl.py#line=92), in current_async_library()
91 return 'curio'
---> 93 raise AsyncLibraryNotFoundError(
94 "unknown async library, or not in async context"
95 )
AsyncLibraryNotFoundError: unknown async library, or not in async context
During handling of the above exception, another exception occurred:
AsyncLibraryNotFoundError Traceback (most recent call last)
Cell In[4], line 9
1 from rcsbapi.data import DataQuery as Query
3 query = Query(
4 input_type="entries",
5 input_ids=["4HHB"],
6 return_data_list=["exptl.method"]
7 )
----> 9 result_dict = query.exec()
10 print(result_dict)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/rcsbapi/data/data_query.py:200](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/rcsbapi/data/data_query.py#line=199), in DataQuery.exec(self, batch_size, progress_bar, max_retries, retry_backoff, max_concurrency)
187 def exec(self, batch_size: int = None, progress_bar: bool = False, max_retries: int = None, retry_backoff: int = None, max_concurrency: int = None) -> Dict[str, Any]:
188 """POST a GraphQL query and get response concurrently using httpx
189
190 Args:
(...) 198 Dict[str, Any]: JSON object containing the compiled query result (aggregated across all sub-requests)
199 """
--> 200 result = asyncio.run(self._async_exec(batch_size=batch_size, progress_bar=progress_bar, max_retries=max_retries, retry_backoff=retry_backoff, max_concurrency=max_concurrency))
202 return result
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/nest_asyncio.py:30](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/nest_asyncio.py#line=29), in _patch_asyncio.<locals>.run(main, debug)
28 task = asyncio.ensure_future(main)
29 try:
---> 30 return loop.run_until_complete(task)
31 finally:
32 if not task.done():
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/nest_asyncio.py:98](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/nest_asyncio.py#line=97), in _patch_loop.<locals>.run_until_complete(self, future)
95 if not f.done():
96 raise RuntimeError(
97 'Event loop stopped before Future completed.')
---> 98 return f.result()
File [~/miniforge3/envs/endgroups/lib/python3.14/asyncio/futures.py:208](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/asyncio/futures.py#line=207), in Future.result(self)
206 self.__log_traceback = False
207 if self._exception is not None:
--> 208 raise self._exception.with_traceback(self._exception_tb)
209 return self._result
File [~/miniforge3/envs/endgroups/lib/python3.14/asyncio/tasks.py:291](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/asyncio/tasks.py#line=290), in Task.__step_run_and_handle_result(***failed resolving arguments***)
289 result = coro.send(None)
290 else:
--> 291 result = coro.throw(exc)
292 except StopIteration as exc:
293 if self._must_cancel:
294 # Task is cancelled right before coro stops.
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/rcsbapi/data/data_query.py:219](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/rcsbapi/data/data_query.py#line=218), in DataQuery._async_exec(self, batch_size, progress_bar, max_concurrency, max_retries, retry_backoff)
215 batched_ids = [self._input_ids]
217 semaphores = asyncio.Semaphore(max_concurrency)
--> 219 async with httpx.AsyncClient(timeout=config.API_TIMEOUT) as client:
220 tasks = []
221 for id_batch in batched_ids:
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py:2016](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_client.py#line=2015), in AsyncClient.__aexit__(self, exc_type, exc_value, traceback)
2008 async def __aexit__(
2009 self,
2010 exc_type: type[BaseException] | None = None,
2011 exc_value: BaseException | None = None,
2012 traceback: TracebackType | None = None,
2013 ) -> None:
2014 self._state = ClientState.CLOSED
-> 2016 await self._transport.__aexit__(exc_type, exc_value, traceback)
2017 for proxy in self._mounts.values():
2018 if proxy is not None:
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_transports/default.py:372](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpx/_transports/default.py#line=371), in AsyncHTTPTransport.__aexit__(self, exc_type, exc_value, traceback)
365 async def __aexit__(
366 self,
367 exc_type: type[BaseException] | None = None,
368 exc_value: BaseException | None = None,
369 traceback: TracebackType | None = None,
370 ) -> None:
371 with map_httpcore_exceptions():
--> 372 await self._pool.__aexit__(exc_type, exc_value, traceback)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py:364](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py#line=363), in AsyncConnectionPool.__aexit__(self, exc_type, exc_value, traceback)
358 async def __aexit__(
359 self,
360 exc_type: type[BaseException] | None = None,
361 exc_value: BaseException | None = None,
362 traceback: types.TracebackType | None = None,
363 ) -> None:
--> 364 await self.aclose()
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py:353](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py#line=352), in AsyncConnectionPool.aclose(self)
351 closing_connections = list(self._connections)
352 self._connections = []
--> 353 await self._close_connections(closing_connections)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py:343](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_async/connection_pool.py#line=342), in AsyncConnectionPool._close_connections(self, closing)
341 async def _close_connections(self, closing: list[AsyncConnectionInterface]) -> None:
342 # Close connections which have been removed from the pool.
--> 343 with AsyncShieldCancellation():
344 for connection in closing:
345 await connection.aclose()
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py:203](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py#line=202), in AsyncShieldCancellation.__init__(self)
198 def __init__(self) -> None:
199 """
200 Detect if we're running under 'asyncio' or 'trio' and create
201 a shielded scope with the correct implementation.
202 """
--> 203 self._backend = current_async_library()
205 if self._backend == "trio":
206 self._trio_shield = trio.CancelScope(shield=True)
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py:30](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/httpcore/_synchronization.py#line=29), in current_async_library()
28 environment = "asyncio"
29 else:
---> 30 environment = sniffio.current_async_library()
32 if environment not in ("asyncio", "trio"): # pragma: nocover
33 raise RuntimeError("Running under an unsupported async environment.")
File [~/miniforge3/envs/endgroups/lib/python3.14/site-packages/sniffio/_impl.py:93](http://localhost:8081/~/miniforge3/envs/endgroups/lib/python3.14/site-packages/sniffio/_impl.py#line=92), in current_async_library()
90 if curio_running():
91 return 'curio'
---> 93 raise AsyncLibraryNotFoundError(
94 "unknown async library, or not in async context"
95 )
AsyncLibraryNotFoundError: unknown async library, or not in async contextReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels