Hi,
my code is trying to upload a file and a data field to a .net API but I am getting an error (see below's output).
User enters the data and file via a web form (using django web framework).
my code is trying to upload a file and a data field to a .net API but I am getting an error (see below's output).
User enters the data and file via a web form (using django web framework).
if 'cert_btn' in request.POST and certificate_form.is_valid():
try:
certificate_password = certificate_form.cleaned_data.get('certificate_password')
print(certificate_password)
print(type(certificate_password))
tenants_id = certificate_form.cleaned_data.get('tenants_id')
print(tenants_id)
file_for_upload = request.FILES['certificate_pfx'].read()
print(type(file_for_upload))
print(file_for_upload)
# files = {
# 'file': open(file_for_upload, 'rb')
# }
x = bearer_token()
request_header = {
# 'Content-Type': 'multipart/form-data',
# 'Ocp-Apim-Subscription-Key': ocp_apim_subscription_key,
'Authorization': 'Bearer ' + x
}
# payload = '{\'payload\': {\'password\': \'' + certificate_password + '\'}}'
payload = {'payload': '{\'password\': \'' + certificate_password + '\'}'}
# payload = {
# 'payload': {
# 'password': certificate_password
# }
# }
message = [
('file', file_for_upload)
]
service_url = str(tenantsservice_url) + 'tenant/' + str(tenants_id) + '/appSettings/ssl-certificate'
print(service_url)
upload_certificate_response = requests.post(service_url, headers=request_header,
data=payload, files=message)Output:"StatusCode":500,"Message":"StartIndex cannot be less than zero.\nParameter name: startIndex"
