Jump to content

Same Automation Services API Call code sometimes works sometimes returns bad request


Stefano Gallo

Recommended Posts

Hi, we are struggling about this problem with Spotfire automation services API Call. The point is that code below works fine in some circumstances, returns 400 bad request error in others even if they're pointing same server and we have still no idea why.

 

import clr

import json

clr.AddReference('System.Web.Extensions')

from System.Web.Script.Serialization import JavaScriptSerializer

from System.Net import *

from System import Convert

from System.Text import Encoding

import urllib

 

# Create a web client

client = WebClient()

 

client_id = "XXXclient_idXXX"

client_secret = "XXXclient_secretXXX"

scope = "api.rest.automation-services-job.execute"

 

 

credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(client_id + ":" + client_secret));

client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;

client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"

 

values = {"client_id" : client_id,

"client_secret" : client_secret,

"scope" : scope,

"grant_type" : "client_credentials"

}

data = urllib.urlencode(values)

 

address = "https://serverdomain/spotfire/oauth2/token"

token = client.UploadString(address,data)

 

Use case #1, One PC two Spotfire Version (10.3, 11.4):

10.3: 400 Bad Request

11.4: works fine

 

Use case #2, Different PC:

10.3: works fine

 

Use case #3, Another Different PC:

10.3: 400 Bad Request

 

Use case #4 Running Code on webplayer:

Works Fine

 

After these use cases we have excluded:

1) Notebook setting issues - same pc, two spotfire version, two different outputs (working vs bad request)

2) Spotfire version issues - same version on two different computers = two different outputs (working vs bad request)

3) Upgraded vs fresh installed Spotfire version: 7.13 10.3 vs 10.2 10.3 produces same results (400 bad requests)

4) Encoding difference: data string equals between working and not working code

 

 

here's the error code:

Traceback (most recent call last):

File "", line 30, in

SystemError: The remote server returned an error: (400) Bad Request .

 

 

System.Net.WebException: The remote server returned an error: (400) Bad Request .

at System.Net.WebClient.UploadDataInternal(Uri address, String method, Byte[] data, WebRequest& request)

at System.Net.WebClient.UploadString(Uri address, String method, String data)

at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)

at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

at Microsoft.Scripting.Interpreter.LightLambda.Run5[T0,T1,T2,T3,T4,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)

at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)

at Microsoft.Scripting.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)

at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)

at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)

at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)

at Spotfire.Dxp.Application.IronPython27.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...