1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00
actix-extras/examples/multipart/client.py

33 lines
839 B
Python
Raw Normal View History

2017-10-19 08:43:50 +02:00
import asyncio
import aiohttp
2017-12-19 18:51:28 +01:00
async def req1():
2017-10-19 08:43:50 +02:00
with aiohttp.MultipartWriter() as writer:
writer.append('test')
writer.append_json({'passed': True})
2017-12-19 18:51:28 +01:00
resp = await aiohttp.ClientSession().request(
2017-10-19 08:43:50 +02:00
"post", 'http://localhost:8080/multipart',
data=writer, headers=writer.headers)
print(resp)
assert 200 == resp.status
2017-12-19 18:51:28 +01:00
async def req2():
2017-10-20 01:22:21 +02:00
with aiohttp.MultipartWriter() as writer:
writer.append('test')
writer.append_json({'passed': True})
writer.append(open('src/main.rs'))
2017-12-19 18:51:28 +01:00
resp = await aiohttp.ClientSession().request(
2017-10-20 01:22:21 +02:00
"post", 'http://localhost:8080/multipart',
data=writer, headers=writer.headers)
print(resp)
assert 200 == resp.status
2017-10-19 08:43:50 +02:00
loop = asyncio.get_event_loop()
2017-10-20 01:22:21 +02:00
loop.run_until_complete(req1())
loop.run_until_complete(req2())