Closed jerryneedell closed 5 years ago
this minor change to adafruit_request.py seems to work both on the RPi and on a metro_m4_airlift. I'll do a bit more testing before submitting a PR.
$ diff adafruit_requests.py ../Adafruit_CircuitPython_Requests/adafruit_requests.py
195c195
< sock.send(b"%s /%s HTTP/1.0\r\n" % (bytes(method,"UTF-8"), bytes(path,"UTF-8")))
---
> sock.send(b"%s /%s HTTP/1.0\r\n" % (method, path))
197c197
< sock.send(b"Host: %s\r\n" % bytes(host,"UTF-8"))
---
> sock.send(b"Host: %s\r\n" % host)
successful run on RPi
pi@gjnpiairlift:~/projects/blinka/airlift $ python3 airlift.py
ESP32 SPI webclient test
ESP32 found and in idle mode
Firmware vers. bytearray(b'1.2.2\x00')
MAC addr: ['0x39', '0xa1', '0xe', '0x33', '0x4f', '0xc4']
Needell Airport RSSI: -47
Needell Airport RSSI: -65
Needell Airport RSSI: -69
Needell Airport RSSI: -80
xfinitywifi RSSI: -81
Connecting to AP...
could not connect to AP, retrying: ('No such ssid', b'Needell Airport')
Connected to Needell Airport RSSI: -44
My IP address is 10.0.0.29
IP lookup adafruit.com: 104.20.39.240
Ping google.com: 40 ms
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
----------------------------------------
This is a test of Adafruit WiFi!
If you can read this, its working :)
----------------------------------------
Fetching json from http://api.coindesk.com/v1/bpi/currentprice/USD.json
----------------------------------------
{'time': {'updated': 'Sep 7, 2019 11:32:00 UTC', 'updatedISO': '2019-09-07T11:32:00+00:00', 'updateduk': 'Sep 7, 2019 at 12:32 BST'}, 'disclaimer': 'This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org', 'bpi': {'USD': {'code': 'USD', 'rate': '10,396.5150', 'description': 'United States Dollar', 'rate_float': 10396.515}}}
----------------------------------------
Done!
Hi there,
thank you for caring about compatibility with CPython.
We just ran into the same issue when still using the original urequests
module while trying to implement a CPython-based test harness for our Terkin Datalogger.
TypeError: %b requires a bytes-like object, or an object that implements __bytes__, not 'str'
So, we are considering to switch over to the adafruit_requests
module instead.
With kind regards, Andreas.
Just for fun , I tried hooking an airlift breakout to a Raspberry Pi Zero.
I then tried running the esp32spi_simpletest.py and ran into an error in requests.
Note -- I realize requests has not be released to PyPI -- I just put adafruit_requests.py in the local folder for this test.
The Aiflift seems to be working fine but the error seems to be a potential Cpython incompatibility in adafruit_requests.
I just wanted to post this for information while I experiment with it.
Not sure if anyone would really want to use an Airlift on an RPi since WiFi Dongles are less expensive, but I thought it worth demonstrating that it could be done....
here is the test code -- essentially esp32spi_simpletest.py