通过requests我收到以下PDF文档,我想要保存:
b'{"data":"JVBERi0xLjUKJeLjz9MKNSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvTGVuZ3RoIDIxNTk+PnN0cmVhbQp4nOVaS28URxBuybe52Mhv8GEOdsBYaU/PdM+DiEtkwDjEYLDBIfhCEEFoJxG55J/kmCM/I78t1c+prra9szZIkaL1rrd3q7/6uuqrfszOp+z746zIWyl42+bH77IHx9lR9ikreFE1Kv8zK/MD+P5jJor8x+znsyJ/Z7/3XXp4W+STTHWKly1+6wwm2YfsVfab7pWLXBvr12/BgZRdl//S57un70W+93uucbGVwbnM0rgu8j9+1YPYfSjyFljnx++zgFBoBCG4yI/77A6r2T57wl7B69z28Uc91os6VgUXDeo5x35iz9nR1H6l4qpG/Zam2MuWC4nsl529LLmq8kbVvK0gxkqVHNLh2hPfLlteddC01nEr2NrwFxyS454QsLIFozKvmorXChzYPq45Qc1ON5G1aX/I3meVKHknB4QYMe2D7AeMWnDIbMCIMdM+yD5gSCW4rBFGhJn2QfYBQxWCNwJFI8JM+yD7AcOmJGDEmGkfZD+MBYe9T0JIQ0ySphG8iax40Q15tc0JahqlIGvTxgieRJIDkiNKCmvDs4hZpX6RfeAR++2TPCZ5JrywvjyPmFfqF9kPPCK/faIFqhXKC2s08Ih4pX6RfeAR++1TPRG9UV5Y50EdEa/UL7IPPGK/faLjuA5SXrhWPI+YV+oX2Q/xwFLuE0lRyZFCQEovu46XQ6245gQ1FQIMbVJtFdEX1TXVfUF0HljErFK/yF7RWgk8iJ4SvRFeSOeBR8wr9YvsFa0Vz4PqieqN8kI6H3hEvFK/yF7RWvE8Ej0RvVFeSOeDOiJeqV9krwjGwIPoOK6DlBeqlcAj5pX6RfZDPLCU+0RSVHKkEHCt1C1vyqFW ..... and much more
wOTgzMjYgMDAwMDAgbiAKMDAwMDA5ODM2NyAwMDAwMCBuIAowMDAwMDk4NTUyIDAwMDAwIG4gCnRyYWlsZXIKPDwvSW5mbyA0MiAwIFIvSUQgWzw4MWNmZjFlOWRjZjlmMzcxZjJkYzNmZTllYWY0MTI1MD48NjNmN2EzMTViNjk5MDBiY2YzZDcxOTUzY2MzZDFmNWQ+XS9Sb290IDQxIDAgUi9TaXplIDQzPj4Kc3RhcnR4cmVmCjk4NTk5CiUlRU9GCg==","documentTemplateType":1459425196590,"mimeType":"application/pdf","title":"title of the pdf"}'
我尝试通过以下方式保存:
response = requests.get(url, headers=self.get_authentication_header(path=path, method="GET"))
with open("my_file.pdf", 'wb') as f:
f.write(response.content)
f.close()
这个方法可以使用,但是PDF文件已经损坏了。我该如何保存这个PDF文件?
response.content
是完整的 JSON。你可能只需要在"data"
键下的值。因此,将其转换为字典并获取该值。 - Yevhen Kuzmovychf.write(response.json()['data'])
。 - Yevhen Kuzmovych