You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
async def async_http_request(self, http_method: Callable, *args, **kwargs) -> any:
"""
Generic method for async HTTP calls, includes error handling.
Parameters
----------
http_method: Callable
HTTP function, e.g., httpx.get or httpx.post.
args:
Any positional arguments for the async HTTP function.
kwargs:
Any keyword arguments for the async HTTP function. Optionally provide
timeout argument, defaults to 10 seconds.
Returns
-------
any
Usually a response type object from the provided async HTTP function.
"""
if 'timeout' not in kwargs:
kwargs['timeout'] = 10
try:
async with httpx.AsyncClient() as client:
if http_method is httpx.get:
httpx_client = client.get
elif http_method is httpx.post:
httpx_client = client.post
else:
raise ValueError("Unsupported HTTP method")
resp = await httpx_client(*args, **kwargs)
except httpx.TimeoutException:
raise GraphQLError(
f"Timeout while connecting to '{kwargs.get('url')}'.",
extensions=GraphQLException.REQUEST_TIMED_OUT.value
)
except self.HTTPX_EXCEPTIONS:
raise GraphQLError(
f"The '{kwargs.get('url')}' endpoint could not be reached.",
extensions=GraphQLException.REQUEST_FAILED.value
)
if resp.status_code != 200:
raise GraphQLError(
resp.text, extensions=GraphQLException.REQUEST_FAILED.value
)
return resp
async def async_get_request(self, url: str, params=None, timeout=10, **kwargs):
"""Sends an async GET request and returns response if successful."""
return await self.async_http_request(httpx.get, url=url, params=params, timeout=timeout, **kwargs)
async def async_post_request(self, url: str, data_payload=None, json_payload=None, timeout=10, **kwargs):
"""Sends an async POST request and returns response if successful."""
return await self.async_http_request(httpx.post, url=url, data=data_payload, json=json_payload, timeout=timeout,
**kwargs)
This happens only when we use the dockerized version of the app, locally with PyCharm it works without an issue. It seems like with docker it is unable to load anyio package through httpcore.
Error:
graphql-async-test-service | ERROR:graphql_service.components.location_reference_service.queries.location_reference_service:>>> THREAD 281473214135600 - PID 22 - ERROR: 'LrsQuery.resolve_getLocationReferenceDataForGeodetic
graphql-async-test-service | Traceback (most recent call last):
graphql-async-test-service | File "/app/graphql_service/manager_libraries/base.py", line 119, in async_http_request
graphql-async-test-service | resp = await httpx_client(*args, **kwargs)
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1848, in post
graphql-async-test-service | return await self.request(
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1530, in request
graphql-async-test-service | return await self.send(request, auth=auth, follow_redirects=follow_redirects)
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1617, in send
graphql-async-test-service | response = await self._send_handling_auth(
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1645, in _send_handling_auth
graphql-async-test-service | response = await self._send_handling_redirects(
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects
graphql-async-test-service | response = await self._send_single_request(request)
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1719, in _send_single_request
graphql-async-test-service | response = await transport.handle_async_request(request)
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 366, in handle_async_request
graphql-async-test-service | resp = await self._pool.handle_async_request(req)
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 224, in handle_async_request
graphql-async-test-service | async with self._pool_lock:
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpcore/_synchronization.py", line 48, in __aenter__
graphql-async-test-service | self.setup()
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpcore/_synchronization.py", line 41, in setup
graphql-async-test-service | raise RuntimeError(
graphql-async-test-service | RuntimeError: Running under asyncio requires the 'anyio' package to be installed.
graphql-async-test-service |
graphql-async-test-service | During handling of the above exception, another exception occurred:
graphql-async-test-service |
graphql-async-test-service | Traceback (most recent call last):
graphql-async-test-service | File "/app/graphql_service/utilities/threading_decorators.py", line 127, in add_traceback
graphql-async-test-service | return await coro(*args, **kwargs)
graphql-async-test-service | File "/app/graphql_service/components/location_reference_service/queries/location_reference_service.py", line 75, in resolve_getLocationReferenceDataForGeodetic
graphql-async-test-service | return await location_reference_service_manager.get_lrs_data(
graphql-async-test-service | File "/app/graphql_service/manager_libraries/location_reference_service.py", line 71, in get_lrs_data
graphql-async-test-service | resp = await self.async_post_request(url=self.get_lrs_data_endpoint, json_payload=payload, timeout=30)
graphql-async-test-service | File "/app/graphql_service/manager_libraries/base.py", line 144, in async_post_request
graphql-async-test-service | return await self.async_http_request(httpx.post, url=url, data=data_payload, json=json_payload, timeout=timeout,
graphql-async-test-service | File "/app/graphql_service/manager_libraries/base.py", line 119, in async_http_request
graphql-async-test-service | resp = await httpx_client(*args, **kwargs)
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 2003, in __aexit__
graphql-async-test-service | await self._transport.__aexit__(exc_type, exc_value, traceback)
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 345, in __aexit__
graphql-async-test-service | await self._pool.__aexit__(exc_type, exc_value, traceback)
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 327, in __aexit__
graphql-async-test-service | await self.aclose()
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 312, in aclose
graphql-async-test-service | async with self._pool_lock:
graphql-async-test-service | File "/usr/local/lib/python3.9/site-packages/httpcore/_synchronization.py", line 53, in __aenter__
graphql-async-test-service | await self._anyio_lock.acquire()
graphql-async-test-service | AttributeError: 'AsyncLock' object has no attribute '_anyio_lock'
If needed, I can provide the dockerized application to test.
This discussion was converted from issue #2907 on October 30, 2023 11:50.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The starting point for issues should usually be a discussion...
I've use the following requirements with my project:
requirements.txt
Relevant Code:
This happens only when we use the dockerized version of the app, locally with PyCharm it works without an issue. It seems like with docker it is unable to load anyio package through httpcore.
Error:
If needed, I can provide the dockerized application to test.
Beta Was this translation helpful? Give feedback.
All reactions