I am trying to read the response object using Micropython/Thonny. I am using the requests library. I need to process https, not just http.
urequest doesn't work. SSL doesn't work. urllib, urllib2, urllib3 don't work.
When I use requests, the text attribute, I get the error
Traceback (most recent call last):
File "<stdin>", line 22, in <module>
AttributeError: 'Response' object has no attribute 'text'
Here is the code:
import network,socket,requests
from machine import Pin
sta_if = network.WLAN(network.STA_IF)
ap = network.WLAN(network.AP_IF) # create access-point interface
ap.active(False) # deactivate the interface
gotthrough=False
if not sta_if.isconnected():
sta_if.active(True)
while not gotthrough:
try:
print('connecting to network...')
sta_if.connect('<SSID>', '<password>') # ADAPT
while not sta_if.isconnected():
pass
gotthrough=True
except:
gotthrough=False
theresponse=requests.get('https://cecilchua.online/arduino/arduinoregister.php?boardid=00-00-00-00-00-00')
print(theresponse.text)
theresponse.content is empty. A visit to the URL will reveal it generates text, so it should not be empty. theresponse.json() etc. likewise don't return anything.
I have tried creating my own client using import ssl.
Essentially same code, but remove the requests and import ssl. Then:
sl=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s=ssl.wrap_socket(sl)
I get:
Traceback (most recent call last):
File "<stdin>", line 21, in <module>
File "ssl.py", line 1, in wrap_socket
File "ssl.py", line 1, in wrap_socket
OSError: (-537093200, 'MBEDTLS_ERR_UNKNOWN (0x6400)+MBEDTLS_ERR_UNKNOWN (0x20030050)')
Anyone know how I can fix this or move forward? All I want to do is use Micropython to connect to a HTTPS web page and read the content.