Uploading attachments via Python

I am trying to use the API to upload attachments to a page but running into issue. Looking for any tips anyone has to get this working. I am using the requests packages in Python. Here is the code I’m using, but when I run it with a new file, it returns a 404 status code. If I run it with a file that already is attached to the page, I get the expected 201 status code, but the attachment is never updated regardless.

r = requests.put(https://mywiki.com/rest/wikis/xwiki/spaces/A/spaces/B/spaces/C/pages/WebHome/attachments/test.png, headers={'content-type': 'image/png'}, data=open('/path/to/file.png', 'rb').read())

I can confirm the API is working as I’m able to retrieve a list of attachments using it. Just not uploading anything.