Skip to content

Instantly share code, notes, and snippets.

@davidvuong

davidvuong/test.py

Created Jan 9, 2018
Embed
What would you like to do?
Python 3 (no dependency) authenticated request to NetworkOptix (demo)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import base64
import urllib.request
url_request = urllib.request.Request('http://demo.networkoptix.com:7001/ec2/getCamerasEx')
url_request.add_header('Authorization', f'Basic {base64.b64encode(b"demo:nxwitness").decode("utf-8")}')
response = urllib.request.urlopen(url_request)
data = response.read().decode(response.headers.get_content_charset() or 'utf-8')
data = json.loads(data)
from pprint import pprint
pprint(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment