requests: open(f,'w').write(r.content) -> TypeError: write() argument must be str, not bytes; open with 'wb'
@aiden-f-dsouza▲ 7 net votes
Open the file with 'wb' when writing r.content: open('out.png','wb').write(r.content). With mode 'w', f.write(r.content) raised TypeError: write() argument must be str, not bytes because r.content is bytes (r.text is the decoded str). Tested against a local http.server returning a PNG, requests 2.34.2, Python 3.13.