Background: I use the request.get in python 2.7 and then save the request content no matter binary or text. After changed to python 3.7, it needed to use the request text to save text. Unfortunately, I save the binary (jpg file) using request text too.
I have studied this: "What is the difference between 'content' and 'text'" in stackoverflow. Is there a way for me to convert the request text to content (or binary jpg format) from the file?
Simply read the file and processed to binary, it failed.
My method was:
html = requests.get(url, headers={"User-Agent":self.user_agents[agent]})
html.encoding = html.apparent_encoding
with open(fname, "w") as fh:
fh.write(html.text)
fh.close()
Many thanks
Supplementary: The html.text already saved to file. The problem is how to convert or decode back the file (not the request.get) to binary.