adafruit / Adafruit_CircuitPython_Requests

Requests-like interface for web interfacing
MIT License
51 stars 36 forks source link

object has no attribute 'request' #61

Closed officiallymarky closed 3 years ago

officiallymarky commented 3 years ago

I am trying to do a very basic import requests and query a url and I'm getting an error:

File "adafruit_requests.py", line 692

AttributeError: 'NoneType' object has no attribute 'request'

My code is super simple.

import adafruit_requests as requests
response = requests.get('http://wifitest.adafruit.com/testwifi/index.html')

I am using this on a MagTag with the latest stable UF2 loader, and latest adafruit_request.mpy I can find.

anecdata commented 3 years ago

There needs to be code to include the kind of interface you are using, since there's no OS providing a connection and sockets. In this case, the native networking modules of the ESP32-S2 are needed. There are helper libraries for the MagTag, see: https://learn.adafruit.com/adafruit-magtag/circuitpython-libraries-2 Or, at a low level, use something more like:

import wifi
import socketpool
import ssl
import adafruit_requests

pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
response = requests.get(URL)

Check out the Adafruit Learn Guides and examples for MagTag.

Closing.

officiallymarky commented 3 years ago

You can't use it with magtag.network.connect()?

anecdata commented 3 years ago

As I mentioned above, you can use the higher-level helper libraries, like MagTag and PortalBase. I'd suggest looking at some of the MagTag Learn Guides, or go on Discord to ask support questions.