Comments (7)
hashlib
seems to be used for web sockets. If you're not using web sockets, I think you could comment it out.
edit: ah, I see you did it :-)
Raspberry Pi Pico W has hashlib
, so it may just be a build config that could be changed to include hashlib
in the builds for the WIZnet Pico boards (5100S, 5500, 6100).
edit: looks like a one-line addition needed in the circuitpython
repo in each board's mpconfigboard.mk
file:
CIRCUITPY_HASHLIB = 1
edit 2: This library should probably adopt your change. The websocket example in this repo expects native wifi, not sure offhand if it works on Ethernet. If it does, the core change noted above could be made.
from adafruit_circuitpython_httpserver.
I think it's worth adding the try/except even if we can enable hashlib on the currently remaining devices that don't have it. We have adafruit_hashlib as a python level lib so in the event that any boards are released that actually don't (or can't) support the native hashlib it'll be nice to have this as a fallback.
Makes sense. I will make a PR later in the day.
If I am correct, hashlib is only used for Websockets, so maybe it both hashlib
and adafruit_hashlib
are not present, we could print a warning that Websockets will not work and not require everyone to install it, it they are only using the standard HTTP communication.
So maybe something like this:
try:
import hashlib
except ImportError:
try:
import adafruit_hashlib as hashlib
except ImportError:
print("Warning...")
What do you think?
from adafruit_circuitpython_httpserver.
I agree it makes sense to import flexibly here. It's even conceivable that this library is used with a main board without hashlib
with an ethernet feathering (or other compatible ethernet peripheral).
I started a PR for the core changes, but didn't have all the pieces to test it on an EVB-Pico. I can put it through and leave testing open.
There's about an order of magnitude improvement with the core module over the library:
EXPAND...
import time
GUID = b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
ITERATIONS = 10_000
def hashme():
key = "dGhlIHNhbXBsZSBub25jZQ=="
start = time.monotonic_ns()
for _ in range(0, ITERATIONS):
response_key = hashlib.new("sha1", key.encode())
response_key.update(GUID)
return time.monotonic_ns() - start
import hashlib
duration = hashme()
print(f"{ITERATIONS} iterations in {duration} ns - hashlib")
import adafruit_hashlib as hashlib
duration = hashme()
print(f"{ITERATIONS} iterations in {duration} ns - adafruit_hashlib")
10000 iterations in 500976562 ns - hashlib
10000 iterations in 6370117187 ns - adafruit_hashlib
Addendum: circuitpython
PR adafruit/circuitpython#8719 but there's not enough space on some language builds and there are no other optional modules to remove to make space, I'll see if one of the core devs has an idea
Addendum 2: it wasn't a space issue, seems more like a build dependency issue from using mbedtls for hashlib, details in the PR
from adafruit_circuitpython_httpserver.
There's a native solution at this core PR:
adafruit/circuitpython#8749
If someone is set up to test, please comment there.
from adafruit_circuitpython_httpserver.
I replaced import hashlib
line in the adafruit_httpserver/response.py with following code and it workaround works for me.
However I just want to run web server, so I haven't tested about the WebSocket functions (sorry...).
try:
import hashlib
except ImportError:
import adafruit_hashlib as hashlib
from adafruit_circuitpython_httpserver.
@Akkiesoft Could you please check if the websocket example works WIZnet Pico boards you have?
@anecdata Do you think adding the try/except to import si the way to go, or should it be solved using by adding hashlib during build to boards that do not have it now?
from adafruit_circuitpython_httpserver.
I think it's worth adding the try/except even if we can enable hashlib on the currently remaining devices that don't have it. We have adafruit_hashlib as a python level lib so in the event that any boards are released that actually don't (or can't) support the native hashlib it'll be nice to have this as a fallback.
from adafruit_circuitpython_httpserver.
Related Issues (20)
- Create an httpserver_simpletest example HOT 7
- How do I safely disable all access to filesystem? HOT 1
- Rapid requests causing hangs HOT 2
- PyPi Release not importable
- Setting the hostname - Pico W HOT 2
- mdns setting error - trying to set a custom hostname HOT 5
- Yielding data from an async task to a chunked response HOT 24
- Release notes has bad link to Docs HOT 2
- Submitting empty form, or forms with only checkboxes, causes crash in web server HOT 2
- request.form_data.get(...) returns the string "None" if a field doesn't exist HOT 2
- instructions error HOT 1
- Simple Test (examples/httpserver_simpletest_auto.py) error on M5stack Timer Camera X HOT 2
- CircuitPython 9.0.0 will require SO.REUSEADDR for socket reuse HOT 1
- Airlift Support? HOT 11
- HTTPS Server now works on ESP32-S3 but MemoryError on Pico W and ESP32-S2
- Pico W EOPNOTSUPP On CircuitPython 9.0.0 HOT 2
- HTTPServer stops working on CircuitPython version >= 9.0 HOT 3
- RPI Pico W Circuitpython Webserver on AP HOT 5
- add support for "multipart/x-mixed-replace" (for streaming video) HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adafruit_circuitpython_httpserver.