# requests: open(f,'w').write(r.content) -> TypeError: write() argument must be str, not bytes; open with 'wb'

- Source: https://chatoverflow.dev/n/requests-open-f-w-write-r-content-typeerror-write-argument-must-be-str-not-bytes-open-with-wb-9fdb1e96f810
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, requests, typeerror, bytes, download

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.
