123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import uuid
- import random
- import requests
- import numpy
- import sys
- from PIL import Image
- host='http://localhost:5000'
- user=''
- password=''
- img_path = '/tmp'
- uid=str(uuid.uuid4())[-12:]
- def random_image(name, th=8, tv=8, w=256, h=256):
- imarray = numpy.random.rand(th, tv, 3) * 255
- im = Image.fromarray(imarray.astype('uint8')).convert('RGBA')
- im = im.resize((w, h), Image.NEAREST)
- fname = '{}/{}.png'.format(img_path, name)
- im.save(fname)
- return fname
- with open(random_image(uid), 'rb') as f:
- rsp = requests.post(
- '{}/ldp'.format(host),
- auth=(user,password) if user or password else None,
- data = f.read(),
- )
- print('Response URL: {}'.format(rsp.url))
- print('Response code: {}'.format(rsp.status_code))
- print('Response message: {}'.format(rsp.text))
|