You need to sign in to do that
Don't have an account?
“403::Unknown client” Error When Connecting to Streaming API Push Topic
I am trying to connect to a Push Topic via the Salesforce Streaming API using Python. My application completes the initial handshake correctly, but then fails on the following connect call, with the error: "403::Unknown client".
My messages work as follows:
Handshake Request
Connect Request
https://success.salesforce.com/issues_view?id=a1p30000000T0F0AAK
And read through the documentation, including:
http://www.salesforce.com/developer/docs/api_streaming/Content/DebuggingStreamingAPIApplications.htm
After reading this however, I am no closer to determining what the actual fault or problem is, or how to remedy it.
I have tried a lot of different things and am at a loss at how to get it to work. I am using this Bayeux client library https://github.com/dkmadigan/python-bayeux-client, with some custom amendments to get the authentication working.
Any help would be greatly appreciated.
My messages work as follows:
Handshake Request
{ "channel":"/meta/handshake", "id":"1", "supportedConnectionTypes":["long-polling"], "version":"1.0", "minimumVersion":"1.0" }Handshake Response
{ "channel":"/meta/handshake", "clientId":"xxx", "version":"1.0", "successful":true, "minimumVersion":"1.0", "id":"1", "supportedConnectionTypes":["long-polling"] }It's completed the handshake fine. And then...
Connect Request
{ "channel":"/meta/connect", "clientId":"xxx", "id":"2", "connectionType":"long-polling" }Connect Response
{ "channel":"/meta/connect", "clientId":"xxx", "advice":{ "reconnect":"handshake", "interval":500 }, "error":"403::Unknown client", "successful":false, "id":"2" }I have seen this issue here:
https://success.salesforce.com/issues_view?id=a1p30000000T0F0AAK
And read through the documentation, including:
http://www.salesforce.com/developer/docs/api_streaming/Content/DebuggingStreamingAPIApplications.htm
After reading this however, I am no closer to determining what the actual fault or problem is, or how to remedy it.
I have tried a lot of different things and am at a loss at how to get it to work. I am using this Bayeux client library https://github.com/dkmadigan/python-bayeux-client, with some custom amendments to get the authentication working.
Any help would be greatly appreciated.
Did you resolve this issue? Any help will be greatly appreciated.
I encountered the same error message and the solution in my case was to use the correct header value for the OAuth token. The rest API uses "Authorization: Bearer <Token>" so I was using that for connecting to the streaming API also. Turns out the streaming API uses "Authorization: OAuth <Token>" Instead. I switched it over to "Authorization: OAuth <Token>" and it started working
For those who are still struck at this issue-> This issue results wheneva cometd is not configured properly or the libraries are not loaded properly.
If you configuration is correct, try the handshake once all libraries are loaded fully.
Delay solves my issue. LIke Sumit said, I guess it is because the libraries are not loaded properly. But how can I know 2000 is enough for complete loading?
Please post here if you figure out something, and I'll do the same.
I'm having the same issue with subscriptions, I can't figure it out yet how to make it work.
I'll keep You post on this as well.
Regards.
Thanks
For those who continue to face error 403, there's a fix that worked for me. its mentioned below
- whenever 403 error occurs you will be getting connection broken. SO do one thing add listener metaUnSucessfulListener.
Once you recieve the error, the method will get called and in this method first unsubsicribe the existing insance of cometd, create fresh instance.
function unsubscribe() {
cometd.disconnect(true);
}
function metaUnSucessfulListener(message) {
console.log(
'DEBUG: /meta/unsuccessful Error: ' +
JSON.stringify(message) + ' <br>');
unsubscribe();
setTimeout( function(){
console.log('init of pt failed');
initialize();},10000);
};
function initialize() {
cometd = new dojox.CometD();
cometd.websocketEnabled = false;
token = '{!$Api.Session_ID}';
auth = 'OAuth ' + token;
cometd.configure({
url: cometdURL,
requestHeaders: {
Authorization: auth
},
appendMessageTypeToURL: false,
stickyReconnect: false,
logLevel: "info"
});
cometd.addListener('/meta/connect',
_metaConnect);
cometd.addListener('/meta/handshake',
metaHandshakeListener);
cometd.addListener('/meta/disconnect',
metaDisconnectListener);
cometd.addListener('/meta/subscribe',
metaSubscribeListener);
cometd.addListener('/meta/unsubscribe',
metaUnSubscribeListener);
cometd.addListener('/meta/unsuccessful',
metaUnSucessfulListener);
try {
cometd.handshake();
} catch (e) {
cometd.handshake();
console.log(e);
}
}
Thanks Pat. I did try that to no avail. For completeness, heres my requests/responses:
handshake:
req:
[
{
"channel":"/meta/handshake",
"supportedConnectionTypes":[
"long-polling"
],
"version":"1.0",
"id":"2"
}
]
response:
[
{
"ext":{
"replay":true,
"payload.format":true
},
"minimumVersion":"1.0",
"clientId":"3j91sicmk06mia9pp9cnsgi39ahs",
"supportedConnectionTypes":[
"long-polling"
],
"channel":"/meta/handshake",
"id":"2",
"version":"1.0",
"successful":true
}
]
Connect:
request
[
{
"channel":"/meta/connect",
"connectionType":"long-polling",
"advice":{
"timeout":0
},
"id":"3",
"clientId":"3j91sicmk06mia9pp9cnsgi39ahs"
}
]
response:
[
{
"advice":{
"interval":0,
"reconnect":"handshake"
},
"channel":"/meta/connect",
"id":"3",
"error":"403::Unknown client",
"successful":false
}
]
Then on the server-side, you have your APEX class:
Hope that helps.
The application completes the initial handshake correctly, and everytime it received a "403::Unknown client" message on /meta/connect it re-handshake correctly:
07:04:46.528 Received messages [{clientId=xxx, channel=/meta/connect, id=664, successful=true}]
07:04:46.558 Received messages [{advice={reconnect=handshake, interval=0}, channel=/meta/connect, id=665, error=403::Unknown client, successful=false}]
07:04:46.587 Received messages [{ext={replay=true, payload.format=true}, minimumVersion=1.0, clientId=xxx, supportedConnectionTypes=[Ljava.lang.Object;@565cfe39, channel=/meta/handshake, id=666, version=1.0, successful=true}]
07:04:46.610 Received messages [{clientId=xxx, advice={reconnect=retry, interval=0, timeout=110000}, channel=/meta/connect, id=667, successful=true}]
07:06:36.635 Received messages [{clientId=xxx, channel=/meta/connect, id=668, successful=true}]
The problem is after the second handshake, no event is received from other channel. According to the log above, it seems that the reconnection works fine. Any ideas?