Saving response from Requests to file

前端 未结 2 1962
你的背包
你的背包 2020-12-16 09:46

I\'m using Requests to upload a PDF to an API. It is stored as \"response\" below. I\'m trying to write that out to Excel.

import requests

files = {\'f\': (         


        
2条回答
  •  半阙折子戏
    2020-12-16 10:23

    You can use the response.text to write to a file:

    import requests
    
    files = {'f': ('1.pdf', open('1.pdf', 'rb'))}
    response = requests.post("https://pdftables.com/api?&format=xlsx-single",files=files)
    response.raise_for_status() # ensure we notice bad responses
    file = open("resp_text.txt", "w")
    file.write(response.text)
    file.close()
    file = open("resp_content.txt", "w")
    file.write(response.text)
    file.close()
    

提交回复
热议问题