Write text file

response = requests.get("https://somedomain.com/somepage")		# Get something you want to store
file1 = open("response.txt", "w")
file1.write(response.text)
file1.close()

//Or, using with (handles close for you whatever happens):
with open("response.txt", "w") as file1:
	file1.write(response.text)

Write binary file

# Request the profile picture of the OP:
response = requests.get("https://somedomain.com/someimage.jpg")		# Get a file you want to store
file1 = open("response.jpg", "wb")
file1.write(response.content)
file1.close()

//Or, using with (handles close for you whatever happens)
with open("response.jpg", "wb") as file1:
	file1.write(response.content)
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *