Published on

How to write http response to a file

Authors
  • avatar
    Name
    Saad Bash

For text response: use response.text

response = requests.get("https://api.github.com/users/saadjs")

with open("response.txt", "w") as f: # 'w' for write file permission
    f.write(response.text)

To append to a file:

response = requests.get("https://api.github.com/users/saadjs")

with open("response.txt", "a") as f: # 'a' for append file permission
    f.write(response.text)