'Uploading to anonfiles API with curl in python

I want to upload to anonfiles using the requests module. Code runs but the files don't appear on the website. Here's my code so far:

import requests

files = {
    'file': ('file.txt', open('file.txt', 'rb')),
}
requests = requests.post('https://api.anonfiles.com/upload/?token=mytoken', files=files)

Any ideas as to what could be the problem? Thanks in advance!



Solution 1:[1]

You use wrong URL - it has to be without / at the end.

https://api.anonfiles.com/upload

And it seems it works also without token

import requests

files = {
    'file': ('file.txt', open('file.txt', 'rb')),
}

url = 'https://api.anonfiles.com/upload'
response = requests.post(url, files=files)

data = response.json()

print(data['data']['file']['url']['short'])

Doc: API

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 furas