简体   繁体   English

使用IronPython脚本从Sharepoint将xlsx或csv文件加载到Spotfire中

[英]Loading an xlsx or csv file from Sharepoint into Spotfire using IronPython script

if I try to load the data using below script, the html code is being loaded instead of proper data. 如果我尝试使用以下脚本加载数据,则将加载html代码,而不是正确的数据。 The given link leads to the direct source of xlsx or csv file (if you run that link in the browser, the xlsx or csv file will start downloading automatically). 给定的链接指向xlsx或csv文件的直接来源(如果您在浏览器中运行该链接,则xlsx或csv文件将自动开始下载)。 I would be glad to hear why this kind of situation happens and how to love this problem. 我很高兴听到为什么会发生这种情况以及如何解决这个问题。

import clr
clr.AddReference('System.Net')
from System.Net import HttpWebRequest, NetworkCredential
from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings

readerSettings = TextDataReaderSettings()
readerSettings.Separator = ";"
readerSettings.CultureName = "en-GB"

req = HttpWebRequest.Create("some link to xlsx file")

user_agent = 'individual user-agent'
req.UserAgent = user_agent
req.Method = "GET"

req.UseDefaultCredentials = True
#req.PreAuthenticate = True
user = Document.Properties["Username"]
password = Document.Properties["Password"]

req.Credentials = NetworkCredential(user, password)

rsp = req.GetResponse()
dSource = TextFileDataSource(rsp.GetResponseStream(),readerSettings)
rsp.Close()

dataManager = Document.Data
dataTable = dataManager.Tables[document.Name]
dataTable.ReplaceData(dSource)

the important part of the HTML returned isn't "Javascript is disabled", it's " We can't sign you in because Javascript is disabled." 返回的HTML的重要部分不是“ JavaScript被禁用”,而是“由于Javascript被禁用, 我们无法登录 ”。 based on this it sounds like your issue is that you haven't properly authenticated your session. 基于此,听起来您的问题是您尚未正确验证会话。

I would try to validate by loading this code into the Python IDE of your choice and try it independent of Spotfire. 我将尝试通过将此代码加载到您选择的Python IDE中进行验证,并尝试独立于Spotfire进行尝试。

the correct way to access Sharepoint, most likely, is through the Sharepoint API. 访问Sharepoint的正确方法很可能是通过Sharepoint API。 I don't have experience with this but I'm sure some googling could turn up a solution. 我对此没有经验,但是我敢肯定,通过谷歌搜索可以找到解决方案。 once you have a (third-party library free!) solution working in Python, you can adapt it to Spotfire without too much trouble. 一旦有了使用Python的(免费的第三方库!)解决方案,您就可以在没有太多麻烦的情况下将其适应Spotfire。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM