async def fetch_one(self, url): headers = {'X-TBA-App-Id': self.settings.app_id} #async with curio_http.ClientSession() as session: async with sema, curio_http.ClientSession() as session: response = await session.get(url, headers=headers) content = await response.json() return response, content
async def send_push_async(conditions, content): """ Send data to sashido API. args: conditions: conditions used to send the message content: data that the message will have valid message format: { "where": { "notifications_enabled": true, "channel": "osa" }, "data": { "title": "prueba push desde sqs para python, mensaje 3", "alert": "Nuevo Mensaje SQS", "status": "Nuevo Mensaje SQS" } } """ # async with sema, ... async with curio_http.ClientSession() as session: head = { "X-Parse-Application-Id": APPLICATION_ID, "X-Parse-REST-API-Key": REST_API_KEY, "Content-Type": "application/json" } body = dumps({"where": conditions, "data": content}) response = await session.post(PARSE_URL, headers=head, data=body) content = await response.json() return response.status_code, content
async def fetch_one(self, url): headers = {'X-TBA-App-Id': os.environ['tba']} async with sema, curio_http.ClientSession() as session: response = await session.get(url, headers=headers) content = await response.json() return response, content
async def request(*args, out=None, **kwargs): async with curio_http.ClientSession() as session: response = await session.request(*args, **kwargs) if out: data = await getattr(response, out)() return response, data return response
async def main(): async with curio_http.ClientSession() as session: response = await session.get('https://httpbin.org/get') print('Status code: ', response.status_code) content = await response.json() print('Content: ', content)
async def fetch(url, track_id: str): try: async with curio_http.ClientSession() as session: response = await session.get( url, headers={"WAF-BENCHMARK-TRACK-ID": track_id}) return response.status_code, track_id except Exception as e: log.info(f"ERROR :: {e} :: {url}") print(f"ERROR :: {e} :: {url}") raise WAFBenchmark(e)
async def fetch_one(node_id, url): async with curio_http.ClientSession() as session: status = "" error = "" content = "" try: response = await session.get(url) status = response.status_code content = await response.json() except Exception as e: status = -1 error = e return node_id, status, content, error
async def fetch_one(url): async with curio_http.ClientSession() as session: response = await session.get(url) content = await response.json() return response, content