PDF编码与python请求库已损坏

时间:2015-05-15 18:48:32

标签: python json pdf python-requests

我正在使用Python来请求和迭代JSON响应,然后使用Requests库发送另一个请求,根据JSON中的参数下载文件,如下所示:

url = attachmentIndex['url'] # location of the file
response = requests.get(url, stream=True, auth=('xxxxx', 'xxxxx'))
with open(attachmentIndex['name'], 'wb') as out_file:
    shutil.copyfileobj(response.raw, out_file)
del response

我面临的问题是PDF编码奇怪,如果我尝试打开它,它表明文件已损坏。如果我在文本编辑器中打开已保存的PDF,则下面是顶部内容的屏幕截图:

enter image description here

我能在python中做些什么来正确格式化PDF吗?

0 个答案:

没有答案