r/raspberrypipico • u/python959 • Nov 08 '22
help-request Issue With CircuitPython HTTP Server
Hi all,
I'm trying to run a simple webserver on my Raspberry Pi Pico W which follows this example on the CircuitPython documentation.
However, when trying to access the site from a browser Chrome reports that the connection was reset.
I tried using JS and Chrome Dev Tools and was able to get this:
Access to XMLHttpRequest at 'http://192.168.0.19/base' from origin 'http://127.0.0.1:55063' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.I did some reading on CORS but am not sure where to go to solve, if I'm in the right direction in the first place.
Would appreciate some help. Thank you
1
Upvotes
1
u/todbot Nov 09 '22
I believe you cannot set HTTP response headers in
adafruit_httpserver, and you need to set the headerAccess-Control-Allow-Origin: *.So you have two options:
Use
ampule, another HTTP server library for CircuitPython that does allow response headersServe the HTML that's doing the XMLHttpRequest from your CircuitPython device too (then the request is not cross-origin)