Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Invalid session id" with oauth access token valid for REST #44

Closed
tscizzle opened this issue Jul 13, 2017 · 9 comments
Closed

"Invalid session id" with oauth access token valid for REST #44

tscizzle opened this issue Jul 13, 2017 · 9 comments

Comments

@tscizzle
Copy link

I am using a Salesforce oauth access token for my developer salesforce account, which I know is a valid token because I can query the REST API using it.

But when I do

from urlparse import urlparse
from salesforce_bulk import SalesforceBulk

# `token` is that valid oauth token I mentioned, which works to make calls to REST API
# `instance_url` is something like 'https://na40.salesforce.com'
bulk = SalesforceBulk(sessionId=token, host=urlparse(instance_url).hostname)

# this line then errors
job = bulk.create_insert_job("Contact", contentType='CSV')

"""
BulkApiError: [400] Bulk API HTTP Error result: <?xml version="1.0" encoding="UTF-8"?><error
   xmlns="http://www.force.com/2009/06/asyncapi/dataload">
 <exceptionCode>InvalidSessionId</exceptionCode>
 <exceptionMessage>Invalid session id</exceptionMessage>
</error>
"""

I've seen a lot of questions about Bulk API, and seemingly valid tokens that cause that error.
yatish27/salesforce_bulk_api#33
https://salesforce.stackexchange.com/questions/136150/bulk-api-rejects-seemingly-valid-session-id
https://developer.salesforce.com/forums/?id=906F0000000fyaLIAQ
https://success.salesforce.com/answers?id=9063A000000iUovQAE

But I can't gather what the real answer is. Might this have to do with this Python library, or is it an account settings issue, (or a known API bug)?

@tscizzle
Copy link
Author

Strangely enough, when I do this in my Terminal:
curl https://<instance>.salesforce.com/services/async/40.0/job -H "X-SFDC-Session: <token>" -H "Content-Type: application/xml; charset=UTF-8" -d @job.txt

with my instance and token in the command where it says and , it does NOT give me the "Invalid session id" exception.

(It does give me an error (Unable to parse Job) because I don't have a job.txt, but to confirm that behavior indicates my token worked, I deleted a character from the token to make it obviously a bad token, and it indeed gave me the "Invalid session id" error. So getting a different error like I did about the missing job.text, now indicates that the token is not the issue.)

So now I'm thinking there is an issue in this library. Has anyone else found this to be the case?

@lambacck
Copy link
Contributor

@tscizzle are you using the version out of pypi or the current master? I'd recommend trying with the current master. Also can you use the session Id you have with simple_salesforce to perform a query of any kind?

@tscizzle
Copy link
Author

tscizzle commented Jul 13, 2017

I regular pip installed it, so I guess pypi.

I will try pip installing current master. I will also try a call with simple-salesforce. Thanks, and I'll respond with results!

(And as a follow-up to last message, I actually successfully made the curl call when I added a job.txt, and see the inserted Contacts in my Salesforce account. So my token is fo sho valid for the Bulk API.)

@lambacck
Copy link
Contributor

pip install https://github.com/heroku/salesforce-bulk/archive/9329b2db92006f2708760835c953ad82584b4120.zip

or add https://github.com/heroku/salesforce-bulk/archive/9329b2db92006f2708760835c953ad82584b4120.zip#egg=salesforce-bulk==2.0.0dev4 to requirements.txt

@tscizzle
Copy link
Author

Dope! I did pip install git+https://github.com/heroku/salesforce-bulk and now I can create a job without the sessionId error.

For stability, and anyone else looking at this, I can pip install from the exact archive like you did, instead of from generic latest, which can change in the future.

@tscizzle
Copy link
Author

Just curious, does this work because there's some bug fix on that dev version that's not on pypi yet, but it will be soon?

Not an urgent question cuz I'm all set now, just curious.

I appreciate the prompt help, Chris! You da best.

@lambacck
Copy link
Contributor

Something in #40 could have fixed it. Maybe going to all requests or better header handling or something like that. It's a big PR with lots of changes so it'd be hard to pick out the one thing that did it.

@lambacck
Copy link
Contributor

Superseded by #41 which is tracking release of 2.0 to pypi

@cdcarter
Copy link

The bulk api reports this error on a TLS1.0 connection, or other SSL issues. With the old library, we had to make sure our macOS devs weren't using the system python (https://eclecticlight.co/2016/03/23/the-tls-mess-in-os-x-el-capitan/). I wonder if the switch to requests instead of httplib helps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants