Download and save PDF file with Python requests module
You should use response.content in this case: with open(‘/tmp/metadata.pdf’, ‘wb’) as f: f.write(response.content) From the document: You can also access the response body as bytes, for non-text requests: >>> r.content b'[{“repository”:{“open_issues”:0,”url”:”https://github.com/… So that means: response.text return the output as a string object, use it when you’re downloading a text file. Such as HTML file, etc. … Read more