uploadFile: файл прайс-листа переданный в multipart/form-data
distributorId: Id поставщика
curl -i -X POST -H "Content-Type: multipart/form-data" -F "userlogin=username" -F "userpsw=md5pass" -F "distributorId=329645" -F "uploadFile=@full_path_to_file" https://demo.public.api.ru/cp/distributor/pricelistUpdate
import requests
url = "https://demo.public.api.ru/cp/distributor/pricelistUpdate"
payload={'userlogin': 'username',
'userpsw': 'md5pass',
'uploadFile': 'full_path_to_file',
'distributorId': '329645'}
files=[('uploadFile', ('some_price.xlsx',open(f'{path_to_file}/some_price.xlsx','rb'),'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))]
headers = {
'Content-Type': 'multipart/form-data'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
import asyncio
import logging
import aiohttp
logger = logging.getLogger(__name__)
async def example_upload_price_list(distributor, file_path):
url = f'https://demo.public.api.ru/cp/distributor/pricelistUpdate'
data = {'userlogin': 'login_user',
'userpsw': 'mg5pass',
'distributorId': str(distributor),
'uploadFile': file_path.replace('\\', '/')}
file = open(f"{data['uploadFile']}", "rb").read()
# file = open(f"{data['uploadFile']}", "rb")
try:
async with aiohttp.ClientSession() as session:
with aiohttp.MultipartWriter("form-data") as mp:
for key, value in data.items():
part = mp.append(value)
part.set_content_disposition('form-data', name=key)
mp.append(file)
async with session.post(url, data=mp, headers=mp.headers) as resp:
print(resp)
response = await resp.json()
print(response)
except Exception as e:
print(e)
raise Exception("something went wrong")
if __name__ == '__main__':
loop = asyncio.new_event_loop()
import os
cwd = os.getcwd()
files = os.listdir('files')
for i in range(len(files)):
loop.run_until_complete(example_upload_price_list(distributor=1641804,
file_path=f'{cwd}\\files\\{files[i]}'))