Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Upload files to using python
from requests import Session
import mimetypes
from pathlib import Path
Coded for
def get_mime(f):
return mimetypes.guess_type(f)[0]
s = Session()
api_key = "xxxx"
api_token = "xxxx"
req1_url = "" # get info needed for req2
data = {"api_key": api_key, "api_token": api_token}
req1 =, data=data).json()
if req1['status'] == 'success':
upload_key = req1['result']['upload_key']
cTracker = req1['result']['cTracker']
server_file = req1['result']['server_file']
max_mirrors = req1['result']['max_mirrors'] # max mirror allowed to upload
mirrors = list([k for k, v in req1['result']['mirrors'].items() if v])[:int(max_mirrors)] # create a list of enabled mirror id's with cap based on max_mirrors
if upload_key and cTracker and server_file and mirrors:
f = "C:/Users/0x/Desktop/A CARNE (letra e vídeo) com SEU JORGE, vídeo MOACIR SILVEIRA (320 kbps).mp3"
fn = Path(f).name
print("FILE NAME:", fn)
mime_type = get_mime(f)
print("MIME TYPE:", mime_type)
# file = {"files": open(f,'rb')} # also works
file = {'files': (fn, open(f,'rb'), mime_type)}
# file = {'files': ("new_filename.mp3", open(f,'rb'), mime_type)} # also works
data = {"api_key": api_key, "api_token": api_token, "cTracker": cTracker, "upload_key": upload_key, "mirrors[]": mirrors}
req2 =, files=file, data=data).json()
if req2['status'] == 'success':
# {'status': 'success', 'result': {'name': 'A CARNE (letra e vídeo) com SEU JORGE, vídeo MOACIR SILVEIRA (320 kbps).mp3', 'size': 11929965, 'slug': '3Jcad', 'url': '', 'info': 'complete'}}
print("Error: ", req2)
print("Error data missing: ", upload_key, cTracker, server_file, mirrors)
print("Error: ", req1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment