Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import logging
- import asyncio
- import aiohttp
- from http import HTTPStatus
- logging.basicConfig(format=u'%(levelname)-8s [%(asctime)s] %(message)s', level=logging.INFO)
- BASE_URL = 'http://localhost:8086/{}'
- # BASE_URL = 'https://httpbin.org/anything/{}'
- QUERY = 'query'
- CREATE_DB = 'CREATE DATABASE {}'
- async def createDB(name):
- async with aiohttp.ClientSession() as session:
- payload = {'q': CREATE_DB.format(name)}
- async with await session.post(BASE_URL.format(QUERY), data=json.dumps(payload)) as response:
- if response.status != HTTPStatus.OK:
- logging.error(f'Unexpected response code: {response.status}')
- text = await response.text()
- logging.info(f'Response text:\n{text}')
- loop = asyncio.get_event_loop()
- loop.run_until_complete(createDB('mydb'))
Advertisement
Add Comment
Please, Sign In to add comment