【问题标题】:I'm trying to get an excel sheet downloaded using python requests module and getting junk output我正在尝试使用 python 请求模块下载 excel 表并获取垃圾输出
【发布时间】:2016-08-25 13:57:21
【问题描述】:

我正在尝试下载上传到 Sharepoint 2013 网站的 Excel 文件。

我的代码如下:

import requests
url='https://<sharepoint_site>/<document_name>.xlsx?Web=0'
author = HttpNtlmAuth('<username>','<passsword>')
response=requests.get(url,auth=author,verify=False)
print(response.status_code)
print(response.content)

这给了我一个很长的输出,类似于:

x00docProps/core.xmlPK\x01\x02-\x00\x14\x00\x06\x00\x08\x00\x00\x00!\x00\x7f\x8bC\xc3\xc1\x00\x00\x00"\ x01\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb8\xb9\x01\x00customXml/item1.xmlPK\x05\x06\ x00\x00\x00\x00\x1a\x00\x1a\x00\x12\x07\x00\x00\xd2\xba\x01\x00\x00\x00'

我之前为另一个站点做过类似的事情,我得到了 xml 作为输出,这对我来说是可以接受的,但我不确定如何处理这些数据。

有什么想法可以将其处理为 xlsx 或 xml?

或者也许以其他方式下载 xlsx?(我尝试通过 wget 库进行下载,但 excel 似乎已损坏)

任何想法都会很有帮助。

问候, 卡兰

【问题讨论】:

    标签: python-3.x sharepoint


    【解决方案1】:

    为时已晚,但我遇到了类似的问题...认为这可能对其他人有帮助。

    尝试将输出写入文件或在打印时应用一些编码。

    写入文件:

    file=open("./temp.xls", 'wb')
    file.write(response.content)
    file.close()
    

    file=open("./temp.xls", 'wb')
    file.write(response.text)
    file.close()
    

    使用编码打印

    print ( resp.text.encode("utf-8") )
    

    print ( resp.content.encode("utf-8") )
    

    !进行适当的导入。 ! 尝试 'w' 或 'wb' 进行文件写入。

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      文件似乎已加密,请求无法处理。
      也许网络服务提供了一个用于下载和安全解码的 API。

      【讨论】:

        猜你喜欢
        • 2019-08-30
        • 1970-01-01
        • 2016-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-15
        • 1970-01-01
        • 2014-12-14
        相关资源
        最近更新 更多