-
Notifications
You must be signed in to change notification settings - Fork 17
/
snapshot.py
58 lines (45 loc) · 1.52 KB
/
snapshot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from __future__ import print_function
from foscontrol import Cam
import sys
try: # PY3
from configparser import ConfigParser
except ImportError:
from ConfigParser import SafeConfigParser as ConfigParser
################################
# Don't forget to edit cam.cfg #
# to reflect you setup! #
################################
if __name__ == "__main__":
config = ConfigParser()
# see cam.cfg.example
config.read(['cam.cfg'])
prot = config.get('general', 'protocol')
host = config.get('general', 'host')
port = config.get('general', 'port')
user = config.get('general', 'user')
passwd = config.get('general', 'password')
if sys.hexversion < 0x03040300:
# parameter context not available
ctx = None
else:
# disable cert checking
# see also http://tuxpool.blogspot.de/2016/05/accessing-servers-with-self-signed.html
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
# connection to the camera
do = Cam(prot, host, port, user, passwd, context=ctx)
(img, fnm) = do.snapPicture()
# Possible errors/exceptions:
#
# urllib.error.URLError (e.g. no route to host)
# ssl.CertificateError (e.g. wrong or no ssl certificate)
# img == None (e.g. wrong password)
if img is not None:
print('Writing picture')
open('/tmp/test.jpg', 'wb').write(img)
else:
print('No picture')