Skip to content

Commit 88ccac2

Browse files
committed
Adjusted referer to fix access errors on sony cameras
1 parent 02b0e5a commit 88ccac2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

occameracontrol/camera.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def activate_camera(self, on=True):
104104
url = f'{self.url}/command/main.cgi'
105105
command = 'on' if on else 'standby'
106106
params = {'System': command}
107-
headers = {'referer': f'{self.url}/'}
107+
headers = {'referer': f'{self.url}/index.html'}
108108
auth = HTTPDigestAuth(self.user, self.password) \
109109
if self.user and self.password else None
110110
logger.debug('GET %s with params: %s', url, params)
@@ -113,7 +113,10 @@ def activate_camera(self, on=True):
113113
headers=headers,
114114
params=params,
115115
timeout=5)
116-
response.raise_for_status()
116+
try:
117+
response.raise_for_status()
118+
except requests.exceptions.HTTPError as e:
119+
logger.error('Failed to activate camera: %s', e)
117120

118121
def move_to_preset(self, preset: int):
119122
'''Move the PTZ camera to the specified preset position
@@ -132,7 +135,7 @@ def move_to_preset(self, preset: int):
132135
elif self.type == CameraType.sony:
133136
url = f'{self.url}/command/presetposition.cgi'
134137
params = {'PresetCall': f'{preset},24'}
135-
headers = {'referer': f'{self.url}/'}
138+
headers = {'referer': f'{self.url}/index.html'}
136139
auth = HTTPDigestAuth(self.user, self.password) \
137140
if self.user and self.password else None
138141
logger.debug('GET %s with params: %s', url, params)

0 commit comments

Comments
 (0)