Error 415 uploading audio #611
-
Hello all, import requests
from requests.auth import HTTPDigestAuth
# Configura la dirección IP de la cámara y el puerto
camera_ip = "***.***.**.**"
# Configura las credenciales de autenticación
username = "***"
password = "****"
# Ruta del archivo de audio a enviar
audio_file_path = r"C:\Users\User\Desktop\audio.mp3"
# Establece el boundary para el formulario multipartes
boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW"
# Construye el contenido del formulario multipartes
file_content = open(audio_file_path, "rb").read()
multipart_data = (
f"--{boundary}\r\n"
f"Content-Disposition: form-data; name=\"file\"; filename=\"audio.mp3\"\r\n"
"Content-Type: audio/basic\r\n\r\n"
f"{file_content}\r\n"
f"--{boundary}--\r\n"
)
# Configura la URL para la carga del clip de medios
upload_url = f"http://{camera_ip}/axis-cgi/mediaclip.cgi?action=upload&media=audio"
# Obtiene la longitud del contenido
content_length = len(multipart_data)
# Establece los encabezados de la solicitud
headers = {
"Content-Length": str(content_length),
"Content-Type": f"multipart/form-data; boundary={boundary}"
}
# Crea un objeto de autenticación digest
auth = HTTPDigestAuth(username, password)
# Envía la solicitud POST al endpoint de carga del clip de medios
response = requests.post(upload_url, data=multipart_data, headers=headers, auth=auth)
# Verifica si la carga fue exitosa
if response.status_code == 200:
print("Clip de medios cargado exitosamente.")
else:
print(f"Error al cargar el clip de medios. Código de estado HTTP: {response.status_code}")
print(response.content) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
This automatically generated reply acts as a friendly reminder. Answers to your questions will most often come from the community, from developers like yourself. You will, from time to time, find that Axis employees answers some of the questions, but this is not a guarantee. Think of the discussion forum as a complement to other support channels, not a replacement to any of them. If your question remains unanswered for a period of time, please revisit it to see whether it can be improved by following the guidelines listed in Axis support guidelines. |
Beta Was this translation helpful? Give feedback.
-
Hi @alejandroactisa , curl -u root:pass --digest --noproxy "*" -XPOST 'http://10.176.12.211/axis-cgi/mediaclip.cgi?action=upload&media=audio&name=file1' --header 'Content-Type: multipart/form-data' --form '[email protected]' Tested with AXIS Q1615 Mk III Network Camera (AXIS OS version 11.9.60) Asked ChatGPT to write code 😉import requests
from requests.auth import HTTPDigestAuth
# Define the URL and authentication credentials
url = 'http://10.176.12.211/axis-cgi/mediaclip.cgi?action=upload&media=audio&name=UsingChatGPT'
username = 'root'
password = 'pass'
# Define the file to upload
files = {'Content-Type': open('07.mp3', 'rb')}
# Send the POST request with authentication
response = requests.post(url, auth=HTTPDigestAuth(username, password), files=files)
# Check the response
print(response.text) Guess what it worked 🍾 |
Beta Was this translation helpful? Give feedback.
-
Remember to check OS version, try to use latest active or latest LTS OS. |
Beta Was this translation helpful? Give feedback.
-
Adding another sample inspired from here import requests
from requests.auth import HTTPDigestAuth
camera_ip = "10.176.12.211"
username = "root"
password = "pass"
upload_url = 'http://10.176.12.211/axis-cgi/mediaclip.cgi?action=upload&media=audio&name=Usingfirmware'
audio_file_path = r"s1.mp3"
files = {
'file': [('s1.mp3',open('s1.mp3', 'rb'),'application/octet-stream')],
'name': "Using_firmware_API_reference"
}
auth = HTTPDigestAuth(username, password)
response = requests.post(upload_url, auth=auth,files =[('file',open('s1.mp3', 'rb'))])
print(response.status_code)
print(response.text) |
Beta Was this translation helpful? Give feedback.
Hi @alejandroactisa ,
Not sure how to use cURL in Python but adding my command which I use from WSL:
Tested with AXIS Q1615 Mk III Network Camera (AXIS OS version 11.9.60)
Asked ChatGPT to write code 😉