David Wallace 4 Posted July 5, 2019 Share Posted July 5, 2019 Could not perform action 'Get Quote'. The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.GetResponse() atstub$386##386(Closure , CallSite , CodeContext , Object ) at Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func4 target, CallSite site, Object[] args) at Microsoft.Scripting.Actions.CallSite1.UpdateAndExecute(Object[] args) at Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at $364##364(Closure , Scope , LanguageContext ) at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink) at Spotfire.Dxp.Application.IronPython20.IronPythonScriptEngine.Execute(ScriptDefinition script, Dictionary2 scope) at Spotfire.Dxp.Application.Scripting.ScriptService.Execute(ScriptDefinition script, Dictionary2 scope, InternalLibraryManager internalLibraryManager, NotificationService notificationService) at Spotfire.Dxp.Application.Scripting.ScriptManager.c__DisplayClass4.b__3() at Spotfire.Dxp.Framework.Commands.CommandHistory.Transaction(Executor executor, Boolean visible, Boolean sticky, Guid stickyGuid) at Spotfire.Dxp.Framework.Commands.CommandHistory.Transaction(String displayName, Executor executor) at Spotfire.Dxp.Application.Scripting.ManagedScript.Execute(Dictionary2 environment) at Spotfire.Dxp.Application.HtmlTextAreaControls.ActionControl.ModifyCore(Object value) at Spotfire.Dxp.Application.Visuals.HtmlTextArea.InteractWithControl(String id, Action1 interaction) Link to comment Share on other sites More sharing options...
Shandilya Peddi Posted July 5, 2019 Share Posted July 5, 2019 Looking at the stack trace, I assume you are using IronPython script to make a webrequest and this request seems to be failing with a 400 bad request error. May be you can look into the values that are being passed to you request. Also a fiddler trace might be helpful in this case Link to comment Share on other sites More sharing options...
David Wallace 4 Posted July 5, 2019 Author Share Posted July 5, 2019 Below is the code that I am using. I am new to web technologies. I have a hunch that it is an authentication error. I get this error once I send the request via a webplayer. This code works on spotfire analyst, when i am not on a web browser. The ultimate goal is to use a third party api in spotfire to trigger the execution of a cloud application . import clr clr.AddReference('System.Data') clr.AddReference('System.Web.Extensions') import System from System import DateTime from System.Data import DataSet, DataTable from System.IO import StreamReader, StreamWriter, MemoryStream, SeekOrigin from System.Net import HttpWebRequest from System.Web.Script.Serialization import JavaScriptSerializer from Spotfire.Dxp.Data import DataType, DataTableSaveSettings from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings# get stock quotes data in JSON format from Yahoo Finance API tickerSymbol = Document.Properties["TickerSymbol"] Months = Document.Properties["Months"] startDate = DateTime.Today.AddMonths(-Months).ToString("yyyy-MM-dd") endDate = DateTime.Today.ToString("yyyy-MM-dd") #https://quantprice.herokuapp.com/api/v1.1/scoop/periodtickers=MSFT&begin=2012-02-19 uri = "https://quantprice.herokuapp.com/api/v1.1/scoop/periodtickers=" + tickerSymbol + "&begin=" + startDate webRequest = HttpWebRequest.Create(uri)response = webRequest.GetResponse() streamReader = StreamReader(response.GetResponseStream()) jsonData = streamReader.ReadToEnd() js = JavaScriptSerializer() dataDict = js.Deserialize(jsonData,object) myColName = [] for val in dataDict["datatable"]["columns"]: #print val["name"] myColName.append(val["name"]) print textData = "t".join(myColName) + "rn"# build a string representing the data in tab-delimited text format #textData = "SymboltDatetClosern" for quote in dataDict["datatable"]["data"]: #print "t".join(str(val) for val in quote) textData += "t".join(str(val) for val in quote) + "rn"# make a stream from the string stream = MemoryStream() writer = StreamWriter(stream) writer.Write(textData) writer.Flush() stream.Seek(0, SeekOrigin.Begin)# set up the text data reader readerSettings = TextDataReaderSettings() readerSettings.Separator = "t" readerSettings.AddColumnNameRow(0) readerSettings.SetDataType(0, DataType.String) readerSettings.SetDataType(1, DataType.String) readerSettings.SetDataType(2, DataType.String) readerSettings.SetDataType(3, DataType.String) readerSettings.SetDataType(4, DataType.String) readerSettings.SetDataType(5, DataType.String) readerSettings.SetDataType(6, DataType.Date) readerSettings.SetDataType(7, DataType.Currency) readerSettings.SetDataType(8, DataType.Currency) readerSettings.SetDataType(9, DataType.Currency) readerSettings.SetDataType(10, DataType.Currency) readerSettings.SetDataType(11, DataType.Real)# create a data source to read in the stream textDataSource = TextFileDataSource(stream, readerSettings)# add the data into a Data Table in Spotfire if Document.Data.Tables.Contains("Stock Data"): Document.Data.Tables["Stock Data"].ReplaceData(textDataSource) else: newTable = Document.Data.Tables.Add("Stock Data", textDataSource) tableSettings = DataTableSaveSettings (newTable, False, False) Document.Data.SaveSettings.DataTableSettings.Add(tableSettings) Link to comment Share on other sites More sharing options...
Shandilya Peddi Posted July 5, 2019 Share Posted July 5, 2019 Can you try the below and see if we can gather more information 1. try/except to read more information from the exceptiontry: response = webRequest.GetResponse()except Exception , e: print e.ToString()2. In general an IronPython script triggerred in WebPlayer is executed on the Node Manager machine, as test if possible try to install an Analyst on Nodemanager machine, open the analysis and test with the script executes fine Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now