Skip to content

Commit 5f04a60

Browse files
committed
removed adafruit_binascii now uses built-in binascii
1 parent 1ea79ef commit 5f04a60

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

examples/wifi/expanded/requests_wifi_api_openskynetwork_private_area.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# SPDX-FileCopyrightText: 2024 DJDevon3
22
# SPDX-License-Identifier: MIT
33
# Coded for Circuit Python 8.2.x
4-
"""OpenSky-Network.org Private API Example"""
4+
"""OpenSky-Network.org Private Area API Example"""
55
# pylint: disable=import-error
66

7+
import binascii
78
import os
89
import time
910

1011
import adafruit_connection_manager
1112
import wifi
12-
from adafruit_binascii import b2a_base64
1313

1414
import adafruit_requests
1515

@@ -35,7 +35,8 @@
3535
SLEEP_TIME = 1800
3636

3737
# Set debug to True for full JSON response.
38-
# WARNING: makes credentials visible
38+
# WARNING: makes credentials visible. based on how many flights
39+
# in your area, full response could crash microcontroller
3940
DEBUG = False
4041

4142
# Initalize Wifi, Socket Pool, Request Session
@@ -45,18 +46,17 @@
4546

4647
# -- Base64 Conversion --
4748
OSN_CREDENTIALS = str(osnusername) + ":" + str(osnpassword)
48-
OSN_CREDENTIALS_B = b"" + str(OSN_CREDENTIALS) + ""
49-
BASE64_ASCII = b2a_base64(OSN_CREDENTIALS_B)
50-
BASE64_STRING = str(BASE64_ASCII) # bytearray
51-
TRUNCATED_BASE64_STRING = BASE64_STRING[2:-1] # truncate bytearray head/tail
49+
# base64 encode and strip appended \n from bytearray
50+
OSN_CREDENTIALS_B = binascii.b2a_base64(b"" + str(OSN_CREDENTIALS)).strip()
51+
BASE64_STRING = str(OSN_CREDENTIALS_B) # bytearray
52+
SLICED_BASE64_STRING = BASE64_STRING[2:-1] # slice bytearray head/tail
5253

5354
if DEBUG:
54-
print("Original Binary Data: ", OSN_CREDENTIALS_B)
55-
print("Base64 ByteArray: ", BASE64_ASCII)
56-
print(f"Base64 String: {TRUNCATED_BASE64_STRING}")
55+
print("Base64 ByteArray: ", BASE64_STRING)
56+
print(f"Base64 Sliced String: {SLICED_BASE64_STRING}")
5757

5858
# Area requires OpenSky-Network.org username:password to be base64 encoded
59-
OSN_HEADER = {"Authorization": "Basic " + str(TRUNCATED_BASE64_STRING)}
59+
OSN_HEADER = {"Authorization": "Basic " + str(SLICED_BASE64_STRING)}
6060

6161
# Example request of all traffic over Florida.
6262
# Geographic areas calls cost less against the limit.

0 commit comments

Comments
 (0)