from urllib.request import urlopen with open("data.txt", "rb") as in_fh: data = in_fh.read() url = "https://bpaste.net" urlopen(url, data=data)