implementing AXIS CGI commands using Python Requests with username+password authentication #37
-
Can anyone provide a Python example of a successful http GET request to implement a CGI command? import urllib3 get the status of the responseprint(resp.status) The code connects with the camera server but because there is no username & password authentication, a 401 error is returned: b'<TITLE>401 Unauthorized</TITLE>\n 401 Unauthorized\nYour client does not have permission to get URL /axis-cgi/param.cgi from this server.\n\n'401 |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
You should use Digest access authentication when communicating with the device. Do you want to give it a go, or would you like me to attempt to provide you with an example? |
Beta Was this translation helpful? Give feedback.
-
I really appreciate the advice. Here’s the whole picture:
Initially, we were able to send a cgi commands to the axis camera (firmware 5.5 or greater) using an Arduino type processor. The processor established an ethernet socket type connection, sent the cgi command, authenticated, and then closed the socket.
We could successfully send virtual input change of state commands to the axis camera:
"GET /axis-cgi/admin/virtualinput/activate.cgi?schemaversion=1&port=[port#]"
Or repeatedly send dynamic text commands to embed in the camera image to reflect that status of a process being monitored visually and with performance metrics:
"GET /axis-cgi/dynamicoverlay.cgi?action=settext&text=[text showing operating metrics]"
Previously the camera had been set up to enable dynamic text operation (#D).
This worked, but it is non-deterministic and portions of the code were empirically derived (they work but for unknown reasons). The objective now is to optimize and move this process to python application running on a Linux platform, and do it the right way.
Here is the Arduino code (excerpted) that works adequately (for dynamic text overly):
[see attached pdf]
[Arduino Text Overlay Code.pdf](https://github.com/AxisCommunications/discussions/files/9264467/Arduino.Text.Overlay.Code.pdf)
It seems that we should be able to do this faster and more efficiently using the camera’s VAPIX3 APIs. But authenticating to the camera (username and password) is an elusive puzzle, and I remain unconvinced it can be done using the APIs.
So, alternatively, establishing (or better yet persisting) an ethernet connection to the camera and using the process that appeared to work with the Arduino platform is the current objective.
From: Mattias Kindborg ***@***.***>
Reply-To: AxisCommunications/discussions ***@***.***>
Date: Thursday, August 4, 2022 at 2:22 AM
To: AxisCommunications/discussions ***@***.***>
Cc: Tom Hilleary ***@***.***>, Author ***@***.***>
Subject: Re: [AxisCommunications/discussions] implementing AXIS CGI commands using Python Requests with username+password authentication (Discussion #37)
Basic access authentication over HTTP is not safe, thus devices with newer firmware are configured to only use digest access authentication. You can configure the camera to accept basic access authentication, but I would advice against it.
I'll see if I can create a small sample for you in the upcoming days.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
To start off, I'm not using Create the following files in a directory. requirements.txt
list-camera-parameters.py import requests
import sys
if len(sys.argv) != 4:
print("Usage: list-camera-parameters.py <ip> <username> <password>")
sys.exit(1)
ip = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]
auth = requests.auth.HTTPDigestAuth(username, password)
r = requests.get("http://{}/axis-cgi/admin/param.cgi?action=list&group".format(ip), auth=auth)
print(r.status_code)
print(r.text) Then create and activate a new virtual environment: python3 -m venv env
source env/bin/activate Proceed with installing the required packages: python3 -m pip install -r requirements.txt Then finally run the example with the following command: python3 list-camera-parameters.py <ip> <username> <password> where |
Beta Was this translation helpful? Give feedback.
-
Mattias,
Perfect – just the push I needed to carry forward.
Thanks for so generously lending your obvious expertise.
BTW, where are you located in the world – and are you directly affiliated with AXIS?
Regards,
/T Hilleary
From: Mattias Kindborg ***@***.***>
Reply-To: AxisCommunications/discussions ***@***.***>
Date: Friday, August 5, 2022 at 4:35 AM
To: AxisCommunications/discussions ***@***.***>
Cc: Tom Hilleary ***@***.***>, Author ***@***.***>
Subject: Re: [AxisCommunications/discussions] implementing AXIS CGI commands using Python Requests with username+password authentication (Discussion #37)
To start off, I'm not using urllib3 but instead requests. I'm hoping that urllib3 wasn't a hard requirement.
Create the following files in a directory.
requirements.txt
requests
list-camera-parameters.py
import requests
import sys
if len(sys.argv) != 4:
print("Usage: list-camera-parameters.py <ip> <username> <password>")
sys.exit(1)
ip = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]
auth = requests.auth.HTTPDigestAuth(username, password)
r = requests.get("http://{}/axis-cgi/admin/param.cgi?action=list&group".format(ip), auth=auth)
print(r.status_code)
print(r.text)
Then create and activate a new virtual environment:
python3 -m venv env
source env/bin/activate
Proceed with installing the required packages:
python3 -m pip install -r requirements.txt
Then finally run the example with the following command:
python3 list-camera-parameters.py <ip> <username> <password>
where <ip> is the IP address, <username> is the username and <password> is the password of the Axis device.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hello everyone! How can I programmatically (Python) impose a dynamically changing text on camera #1 or #2. The AXIS F44 module has 4 video channels |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
To start off, I'm not using
urllib3
but insteadrequests
. I'm hoping thaturllib3
wasn't a hard requirement.Create the following files in a directory.
requirements.txt
list-camera-parameters.py
Then create and activate a new virtual environment:
python3 -m venv env source env/bin/activate
Proc…