Expected UploadFile, received: <class ‘str’>: FastAPI, requests, file-uploads

I’ll tell me story about this error because It’s very confusing and annoying.

What was I doing?
I have a FastAPI server that does file uploads using multipart-formdata. This error came when I tried to create integrations tests to test file uploads using requests. Testing file uploads using the swagger docs was already working perfectly at this point.

Failing code:

import requests
files = {
‘user_id’: (None, ‘5d3928e7-efca-49d1-b311–36b04fbcdf78’),
‘avatar’: (None, open(‘mount/tests/funny-cat.jpg’, ‘rb’)),
}
response = requests.post(‘http://127.0.0.1:10600/v1/photos', files=files)