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
Hello, I just a made an async httpx geocoder since the aiohttp one is not working well (aio-libs/aiohttp#6239). I don't have the time to do all the pr stuff etc, so if someone wants to implement it, do it, here's the code:
fromgeopy.adaptersimportBaseAsyncAdapter, _normalize_proxiesimportjsontry:
importhttpxhttpx_available=TrueexceptImportError:
httpx_available=FalseclassAsyncHttpxAdapter(BaseAsyncAdapter):
is_available=httpx_availabledef__init__(self, *, proxies, ssl_context):
ifnothttpx_available:
raiseImportError(
"`httpx` must be installed in order to use AsyncHttpxAdapter. ""If you have installed geopy via pip, you may use ""this command to install httpx: "'`pip install httpx`.'
)
proxies=_normalize_proxies(proxies)
super().__init__(proxies=proxies, ssl_context=ssl_context)
self.proxies=proxiesself.ssl_context=ssl_context@propertydefsession(self):
# Lazy session creation, which allows to avoid "unclosed socket"# warnings if a Geocoder instance is created without entering# async context and making any requests.session=self.__dict__.get("session")
ifsessionisNone:
session=httpx.AsyncClient(
trust_env=False, # don't use system proxies
)
self.__dict__["session"] =sessionreturnsessionasyncdef__aenter__(self):
returnselfasyncdef__aexit__(self, exc_type, exc_val, exc_tb):
awaitself.session.aclose()
asyncdefget_text(self, url, *, timeout, headers):
response=awaitself.session.get(
url,
timeout=httpx.Timeout(timeout),
headers=headers
)
returnresponse.textasyncdefget_json(self, *args, **kwargs):
returnjson.loads(awaitself.get_text(*args, **kwargs))
The text was updated successfully, but these errors were encountered:
KostyaEsmukov
changed the title
Httpx geocoder to be implemented
Httpx adapter to be implemented
Aug 27, 2023
Hello, I just a made an async httpx geocoder since the aiohttp one is not working well (aio-libs/aiohttp#6239). I don't have the time to do all the pr stuff etc, so if someone wants to implement it, do it, here's the code:
The text was updated successfully, but these errors were encountered: