Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import aiohttp
  2. import asyncio
  3. import async_timeout
  4.  
  5.  
  6. BASE_URL = 'http://localhost:8888'
  7.  
  8. last_name = "Matvienko"
  9. first_name = "Aleksandr"
  10.  
  11. user = {
  12.     "email": "fantom0005@yandex.ru",
  13.     "phone": "88005553535",
  14.     "name": "%s %s Andreevich" % (last_name, first_name),
  15.     "password": "qwerty123",
  16.     "currency": "RUB"
  17. }
  18.  
  19.  
  20. async def fetch(url, json):
  21.     session=aiohttp.ClientSession()
  22.     async with session, asyncio.Semaphore(100), async_timeout.timeout(1500):
  23.         print(f"Current URL {url}")
  24.         try:
  25.             async with session.post(url, json=json) as r:
  26.                 print(r.status)
  27.                 return await r.json()
  28.         except aiohttp.client_exceptions.ClientConnectionError as e:
  29.             print(e)
  30.             return e
  31.         except Exception as e:
  32.             print(e)
  33.             return e
  34.  
  35.  
  36. async def signup(user, session=aiohttp.ClientSession()):
  37.     response = await fetch(f"{BASE_URL}/api/user/signup", user)
  38.     print("asdasjofhaslfdasjnfldask")
  39.     return response
  40.  
  41.  
  42. test = signup(user)
  43.  
  44. print(test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement