-
Notifications
You must be signed in to change notification settings - Fork 35
Removed encoding parameter from bytes call #21
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
Conversation
As dicsussed in adafruit#20, the encoding parameter passed to the `byes` call gives a **TypeError: wrong number of arguments**
Added test for bytearray to keep the existing behavior for strings
Do you know of public API that accepts bytearray data via POST like this that you can share? If so I can test this out with a pyportal. |
I've been testing with the Azure Custom Vision service at customvision.ai. I created a model and posted to the prediction service. Source for how to do it is here: https://github.com/jimbobbennett/mandmcounter This code has my fixed version of adafruit_requests in requests.py. You'd need to create an object detection model in Custom Vision and set the values in the secrets.py file for your WiFi and keys for the model. I'm on a plane at the moment, but tomorrow I can provide detailed instructions on how to do it if that would help. |
Thank you! I think I should be able to get it tested using what you've posted. I will give it a try either tonight or tomorrow. |
I'm ok removing this but would love to see an issue for adding support for the encoding parameter to CircuitPython. In general, we should ensure CircuitPython matches CPython. |
@tannewt - if you look at #20, @FoamyGuy has compared the behavior to CPython and CircuitPython, and the behavior is roughly the same. If you call The difference here is the error given by CircuitPython is different, and less instructive than the CPython one. Where is the right place to raise an issue to get the error message improved? Is it in https://github.com/adafruit/circuitpython? |
@tannewt do you mean adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, and works as expected. I ended up testing with a basic Flask server locally, my msoft account was not allowing me to use Azure without signing up for some more stuff. I was able to verify with these changes to the library we can now use this Circuit Python code:
# ... imports ...
# ... connect to esp and AP etc ...
requests.set_socket(socket, esp)
f = open("small_image.bmp", "rb")
file_data = f.read()
f.close()
copy_data = bytearray(file_data)
response = requests.post("http://192.168.1.117:5000/test", data=copy_data)
print(response)
to POST some image data to a server and we now get the the same (successful) results as this CPython code:
import requests
f = open("small_image.bmp", "rb")
file_data = f.read()
f.close()
copy_data = bytearray(file_data)
r = requests.post("http://localhost:5000/test", data=copy_data)
Whereas prior to these changes it was the error noted in the issue:
File "/lib/adafruit_requests.py", line 285, in post
File "/lib/adafruit_requests.py", line 242, in request
File "/lib/adafruit_requests.py", line 224, in request
TypeError: wrong number of arguments
Ah! Ok. I misunderstood that. Sounds like it is close enough. It would be nice to ensure it is the same exception thrown but it's much less important. This change looks good to me. |
Thank you @jimbobbennett! |
Updating https://github.com/adafruit/Adafruit_CircuitPython_HT16K33 to 3.2.3 from 3.2.2: > Merge pull request adafruit/Adafruit_CircuitPython_HT16K33#66 from FoamyGuy/master Updating https://github.com/adafruit/Adafruit_CircuitPython_IRRemote to 3.4.2 from 3.4.1: > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#33 from mfeif/master Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 6.0.0 from 5.2.0: > Merge pull request adafruit/Adafruit_CircuitPython_BLE#72 from tannewt/remove_radio Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.3.0 from 1.2.0: > Merge pull request adafruit/Adafruit_CircuitPython_Requests#21 from jimbobbennett/master
As dicsussed in #20, the encoding parameter passed to the
byes
call gives a TypeError: wrong number of arguments