If user lacks API permissions we get an ugly error
2022-12-09 11:55:30,684 - ERROR - Error occurred while running gpas-cli
Querying status for 96 sample(s): 0%| | 0/96Traceback (most recent call last):
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py", line 51, in __call__
result = await fn(*args, **kwargs)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/gpas/lib.py", line 190, in fetch_status_single_async
r.raise_for_status() # Raises retryable httpx.HTTPError
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/httpx/_models.py", line 736, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://portal.gpas.ox.ac.uk/ords/gpas_pub/gpasapi/get_sample_detail/bbcb6f25-c1bc-821f-b33d-8ef29d9e266b'
For more information check: https://httpstatuses.com/400
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/gpas/lib.py", line 140, in fetch_status_async
records = [
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/gpas/lib.py", line 141, in <listcomp>
await f
File "/opt/conda/envs/gpas-cli/lib/python3.10/asyncio/tasks.py", line 571, in _wait_for_one
return f.result() # May raise f.exception().
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py", line 86, in async_wrapped
return await fn(*args, **kwargs)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py", line 48, in __call__
do = self.iter(retry_state=retry_state)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/__init__.py", line 363, in iter
raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7f3cce5cf8e0 state=finished raised HTTPStatusError>]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/gpas", line 8, in <module>
sys.exit(main())
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/gpas/cli.py", line 265, in main
defopt.run(
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/defopt.py", line 356, in run
return call()
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/gpas/cli.py", line 240, in download
records = asyncio.run(
File "/opt/conda/envs/gpas-cli/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/opt/conda/envs/gpas-cli/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/gpas/lib.py", line 134, in fetch_status_async
async with httpx.AsyncClient(transport=transport, timeout=30) as client:
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/httpx/_client.py", line 1997, in __aexit__
await self._transport.__aexit__(exc_type, exc_value, traceback)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/httpx/_transports/default.py", line 332, in __aexit__
await self._pool.__aexit__(exc_type, exc_value, traceback)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 326, in __aexit__
await self.aclose()
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 312, in aclose
raise RuntimeError(
RuntimeError: The connection pool was closed while 7 HTTP requests/responses were still in-flight.
Querying status for 96 sample(s): 0%| | 0/96
ERROR: Task exception was never retrieved
future: <Task finished name='Task-12' coro=<fetch_status_single_async() done, defined at /opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py:84> exception=RetryError(<Future at 0x7f3cce5cca30 state=finished raised HTTPStatusError>)>
Traceback (most recent call last):
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py", line 51, in __call__
result = await fn(*args, **kwargs)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/gpas/lib.py", line 190, in fetch_status_single_async
r.raise_for_status() # Raises retryable httpx.HTTPError
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/httpx/_models.py", line 736, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://portal.gpas.ox.ac.uk/ords/gpas_pub/gpasapi/get_sample_detail/970e7724-ad51-9cbb-68d8-2bde9e3485ec'
For more information check: https://httpstatuses.com/400
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py", line 86, in async_wrapped
return await fn(*args, **kwargs)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py", line 48, in __call__
do = self.iter(retry_state=retry_state)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/__init__.py", line 363, in iter
raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7f3cce5cca30 state=finished raised HTTPStatusError>]
ERROR: Task exception was never retrieved
future: <Task finished name='Task-8' coro=<fetch_status_single_async() done, defined at /opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py:84> exception=RuntimeError('Cannot send a request, as the client has been closed.')>
Traceback (most recent call last):
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py", line 86, in async_wrapped
return await fn(*args, **kwargs)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py", line 48, in __call__
do = self.iter(retry_state=retry_state)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/__init__.py", line 351, in iter
return fut.result()
File "/opt/conda/envs/gpas-cli/lib/python3.10/concurrent/futures/_base.py", line 451, in result
return self.__get_result()
File "/opt/conda/envs/gpas-cli/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
raise self._exception
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/tenacity/_asyncio.py", line 51, in __call__
result = await fn(*args, **kwargs)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/gpas/lib.py", line 166, in fetch_status_single_async
r = await client.get(url=url, headers=headers)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/httpx/_client.py", line 1751, in get
return await self.request(
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/httpx/_client.py", line 1527, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/opt/conda/envs/gpas-cli/lib/python3.10/site-packages/httpx/_client.py", line 1603, in send
raise RuntimeError("Cannot send a request, as the client has been closed.")
RuntimeError: Cannot send a request, as the client has been closed.
DEBUG: fetch_status_single_async(): r.status_code=400 r.json()={'message': 'You do not have API access.'}
If user lacks API permissions we get an ugly error