Skip to content

TypeError: wrong number of arguments when posting bytes array #20

Closed
@jimbobbennett

Description

@jimbobbennett

I have a bytearray containing image data from the TTL camera sample. I want to POST this as an octet stream to a REST endpoint.

My code:

import adafruit_requests as requests

...

buffer = bytearray()

headers={
            'Content-Type': 'application/octet-stream',
            'Prediction-Key': prediction_key
        }

r = requests.request('POST', prediction_endpoint, data=buffer, headers=headers)

When I run this I get the following:

......Traceback (most recent call last):
  File "code.py", line 85, in <module>
  File "adafruit_requests.py", line 242, in request
  File "adafruit_requests.py", line 224, in request
TypeError: wrong number of arguments

Running the code locally I've tracked down the error to this line:

if data:
   sock.send(bytes(data, "utf-8"))

If I change the call to bytes() to remove the encoding parameter, it works.

if data:
   sock.send(bytes(data))

Does the CircuitPython implementation of bytes have an encoding parameter?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions