Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this work with fake requests still? #58

Open
tannewt opened this issue Jan 10, 2022 · 5 comments
Open

Does this work with fake requests still? #58

tannewt opened this issue Jan 10, 2022 · 5 comments

Comments

@tannewt
Copy link
Member

tannewt commented Jan 10, 2022

From a user on the forum:

*** USING LOCALFILE FOR DATA - NOT INTERNET!!! ***
Traceback (meest recente call laatst):
  Bestand "code.py", regel 36, in <module>
  Bestand "adafruit_pyportal/__init__.py", regel 310, in fetch
  Bestand "adafruit_portalbase/network.py", regel 509, in check_response
  Bestand "adafruit_portalbase/network.py", regel 535, in _get_headers
AttributeError: 'Fake_Requests' object heeft geen attribuut 'headers'
@dgriswo
Copy link

dgriswo commented Jan 12, 2022

I don't think it ever did. @makermelissa initial commit stores the output of Fake_Requests, which is string. The rest of the library expects response to be an object.

Should Fake_Requests return an object or should PortalBase construct one when Fake_Requests is used?

FWIW, I made it here because the PyPortal library calls PortalBase

@makermelissa
Copy link
Contributor

I think it should return an object. Fake Requests was stripped out of the old PyPortal library and I don't think is actually used much, so likely things have changed without Fake Requests being updated properly.

@Neradoc
Copy link
Contributor

Neradoc commented Mar 27, 2022

The Fake_Requests class is a response currently. We can make it work by adding a headers property and a status_code of 200. While helping somebody on discord, I also made it try to load the file as json and set headers["content-type"] to "application/json" or "text/plain" depending on the result. I can PR that to the library. That would cover the basics of testing the user code with a certain kind of content without having to hit the network.

Though I think it would be interesting for debugging purposes to be able to test headers too, maybe with local_headers.txt being a key/value table of headers (and maybe status code or other).

@dbradmit
Copy link

dbradmit commented Apr 1, 2024

I just got a PyPortal and it seems like this is still an issue. I have been trying to work through adafruit-pyportal/parsing-json and the code fails when trying to use local.txt due to the headers issue regarding fake requests.

I've spent all day trying to debug or fix it on my own without luck. I am clearly missing something basic though as I can't get a working update to network.py. I've tried passing hardcoded headers as well as simply adding print statements to make sure my hardcoded headers match what would be returned by quotes.php but when I compile network.py with mpy-cross and replace the existing network.mpy on my PyPortal with the self-compiled version the updated version never executes.

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Apr 1, 2024

but when I compile network.py with mpy-cross and replace the existing network.mpy on my PyPortal with the self-compiled version the updated version never executes.

@dbradmit are you putting the modified network.py into /lib/adafruit_portalbase/?

If so I think the reason your modified version isn't executing is that adafruit_portalbase is frozen in to the PyPortal build: https://github.com/adafruit/circuitpython/blob/main/ports/atmel-samd/boards/pyportal/mpconfigboard.mk#L15

So the frozen in version takes precedent over the one inside of /lib/.

If you put your modified one at the root of CIRCUITPY it should take precedence over the frozen one. i.e. your device files would be like:

adafruit_portalbase/
lib/
boot_out.txt
code.py

Also during development it's probably easier and more convenient to just skip the mpy-cross step unless you absolutely need it for storage or RAM reasons. The code should function the same in it's .py format which you can then more quickly make edits to during development iterations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants