Merge pull request #3 from Nebukadneza/add_key_url_quoting

URL-Quote the key in HTTP requests
main
kaiyou 6 years ago committed by Alexander Graf
parent 080e76f972
commit 6fadd39aea
No known key found for this signature in database
GPG Key ID: B8A9DC143E075629

@ -3,7 +3,7 @@
import aiohttp import aiohttp
import logging import logging
from urllib.parse import quote
class UrlTable(object): class UrlTable(object):
""" Resolve an entry by querying a parametrized GET URL. """ Resolve an entry by querying a parametrized GET URL.
@ -23,7 +23,8 @@ class UrlTable(object):
if ns is not None: if ns is not None:
key += "/" + ns key += "/" + ns
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(self.url_pattern.format(key)) as request: quoted_key = quote(key)
async with session.get(self.url_pattern.format(quoted_key)) as request:
if request.status == 200: if request.status == 200:
result = await request.json() result = await request.json()
logging.debug("Table get {} is {}".format(key, result)) logging.debug("Table get {} is {}".format(key, result))
@ -40,7 +41,8 @@ class UrlTable(object):
if ns is not None: if ns is not None:
key += "/" + ns key += "/" + ns
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
await session.post(self.url_pattern.format(key), json=value) quoted_key = quote(key)
await session.post(self.url_pattern.format(quoted_key), json=value)
async def iter(self, cat): async def iter(self, cat):
""" Iterate the given key (experimental) """ Iterate the given key (experimental)

Loading…
Cancel
Save