IP camera URL requests

Hey all,
Just wondering what your experience has been with URL requests for IP camera.
I have the following with a HikVision IP camera.
Streaming
rtsp://user:password@192.168.8.100/Streaming/channels/102/httpPreview
→ Works fine in VLC and Mycodo, although I wish I knew how to reduce the resolution to have a more fluid image.
Still capture
http://user:password@192.168.8.100:80/ISAPI/Streaming/channels/102/picture
→ Works fine in this python script:

import pycurl
from io import BytesIO

b_obj = BytesIO()
crl = pycurl.Curl()

#Set URL value
crl.setopt(crl.URL,"http://user:password@192.168.8.100:80/ISAPI/Streaming/channels/102/picture")

#write bytes that are utf-8 encoded
with open('/home/pi/test.jpg','wb') as f:
    crl.setopt(crl.WRITEFUNCTION, f.write)

#Perform a file transfer
    crl.perform()

#end curl session
crl.close()

# get the content stored in the bytesIO object (in byte characters)
get_body = b_obj.getvalue()

print('Output of get request: \n%s' % get_body.decode('utf8'))

→ Doesn’t work in Mycodo > Cameras > urllib:
Error: Could not acquire image.

  • Is there a log where I can see the details of the issue with the still capture?
  • Would using URL requests work better? If so, can anyone recommend the right headers in json (the authentication method is basic or digest)?

PS. Adding the relevant mycodo log. It seems to be a networking-related issue based on some googling…

Mar 09 16:04:20 hydropi python[5597]: 2023-03-09 16:04:18,585 <urlopen error [Errno -2] Name or service not known>
Mar 09 16:04:20 hydropi python[5597]: Traceback (most recent call last):
Mar 09 16:04:20 hydropi python[5597]:   File "/usr/lib/python3.9/urllib/request.py", line 1346, in do_open
Mar 09 16:04:20 hydropi python[5597]:     h.request(req.get_method(), req.selector, req.data, headers,
Mar 09 16:04:20 hydropi python[5597]:   File "/usr/lib/python3.9/http/client.py", line 1255, in request
Mar 09 16:04:20 hydropi python[5597]:     self._send_request(method, url, body, headers, encode_chunked)
Mar 09 16:04:20 hydropi python[5597]:   File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
Mar 09 16:04:20 hydropi python[5597]:     self.endheaders(body, encode_chunked=encode_chunked)
Mar 09 16:04:20 hydropi python[5597]:   File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
Mar 09 16:04:20 hydropi python[5597]:     self._send_output(message_body, encode_chunked=encode_chunked)
Mar 09 16:04:20 hydropi python[5597]:   File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
Mar 09 16:04:20 hydropi python[5597]:     self.send(msg)
Mar 09 16:04:20 hydropi python[5597]:   File "/usr/lib/python3.9/http/client.py", line 950, in send
Mar 09 16:04:20 hydropi python[5597]:     self.connect()
Mar 09 16:04:20 hydropi python[5597]:   File "/usr/lib/python3.9/http/client.py", line 921, in connect
Mar 09 16:04:20 hydropi python[5597]:     self.sock = self._create_connection(
Mar 09 16:04:20 hydropi python[5597]:   File "/usr/lib/python3.9/socket.py", line 822, in create_connection
Mar 09 16:04:20 hydropi python[5597]:     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
Mar 09 16:04:20 hydropi python[5597]:   File "/usr/lib/python3.9/socket.py", line 953, in getaddrinfo
Mar 09 16:04:20 hydropi python[5597]:     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
Mar 09 16:04:20 hydropi python[5597]: socket.gaierror: [Errno -2] Name or service not known

Here is a workaround that does the job, for now.

  1. Set up a server that listens on any port, through nginx or other, and redirects to the folder where you will store the pictures. I use http-server as I’m not conversant enough with nginx. The code simply: python http-server [port] and you will have a server running from wherever the script was executed. e.g. if you place the script in /home/pi/, you can access all the content in the /home/pi/ folder by accessing 127.0.0.1:[port]/.
  2. Take pictures with a python script like the one in the original post, place them in a folder accessible by the server
  3. Enable your scripts to run regularly e.g. with a cron job
  4. Have mycodo access the pictures with urllib at the address http://localhost:[port]/[name of picture].jpg

Not very clean nor secure but it works

Was there not an easy modification to the Function module to fix the error?

I would be happy to look into it, which part of the code is responsible for that?

The urllib camera code is here:

I’ve successfully ported the libcamera functionality to a Function, which is something I plan to do for all the current Camera code, since I’m depreciating the Camera page in favor of standalone Camera Function modules. Here is the first proof of concept Camera Function module for libcamera:

1 Like

Looking forward to this update. I did have the URLrequests and the URLlib camera modules both working in the Cameras Page on my test system, but it seems they have both stopped working for reasons I can not determine :frowning:
I didn’t change any Mycodo settings, and I can still access both the still and stream feeds from the camera manually in a browser, but Mycodo throws an error “could not acquire image” when I try to capture a still or start a stream.
I did run a manual update/upgrade from the console, so I have no idea if that broke something or not. Just been too busy with other things to dig into it.

This Camera Function module is currently available on the master branch. I’ll look into the issue you’re having with the legacy camera system and see if there were any breaking changes introduced.

Can you be more specific about how you’re attempting to do this?

Just using the buttons on the camera modules in the Cameras Page… I had these working for a while, then they just recently stopped working after a couple of recent updates.

I just tested the requests and urllib legacy camera modules are working. These modules haven’t had any changes to their code in a long time, and certainly not any recent software versions.