简体   繁体   English

更改 simple-salesforce 库中的路径

[英]Change path in simple-salesforce library

I am trying to get a report I created on SalesForce via simple_salesforce library in python. I am able to connect successfully.我正在尝试通过 python 中的 simple_salesforce 库获取我在 SalesForce 上创建的报告。我能够成功连接。 However, I get invalid session id error, because the link is wrong, that is created by simple_salesforce.但是,我得到无效的 session id 错误,因为链接是错误的,它是由 simple_salesforce 创建的。 The url I am trying to get is different from what simple_salesforce is searching (which is given in the error below).我尝试获取的 url 与 simple_salesforce 正在搜索的内容不同(在下面的错误中给出)。

The link I am trying to get is: "https://gkg-mfsa.lightning.force.com/lightning/r/Report/00O9N000000JwK2UAK/view?queryScope=userFolders"我试图获得的链接是:“https://gkg-mfsa.lightning.force.com/lightning/r/Report/00O9N000000JwK2UAK/view?queryScope=userFolders”

But the link simple_salesforce is searching is: "https://gkg-mfsa.my.salesforce.com/services/data/v42.0/lightning/r/Report/00O9N000000JwK2UAK/view?queryScope=userFolders" (as given in the error)但是 simple_salesforce 正在搜索的链接是:“https://gkg-mfsa.my.salesforce.com/services/data/v42.0/lightning/r/Report/00O9N000000JwK2UAK/view?queryScope=userFolders”(如错误)

How can I get simple_salesforce library to search for the link I am trying to get instead of what it looks for.我怎样才能让 simple_salesforce 库搜索我试图获取的链接而不是它寻找的内容。

from simple_salesforce import Salesforce


sf = Salesforce(username='myUserName', 
                password='myPassword',
                security_token='mySecurityToken',
               instance_url = "")

report_id = 'myreportId'

sf.restful("lightning/r/Report/ + reportId + /view?queryScope=userFolders")

output output

SalesforceExpiredSession: Expired session for https://gkg-mfsa.my.salesforce.com/services/data/v42.0/lightning/r/Report/00O9N000000JwK2UAK/view?queryScope=userFolders. Response content: [{'message': 'This session is not valid for use with the REST API', 'errorCode': 'INVALID_SESSION_ID'}]


Grab the session id and base endpoint from successful login call从成功的登录调用中获取 session id 和基本端点

session_id, instance = SalesforceLogin(
    username='myemail@example.com',
    password='password',
    security_token='token')

And then run a REST request manually.然后手动运行 REST 请求。 But you'll have to pass the session id as a cookie, not as a "Authorisation Bearer <session_id>" http header.但是您必须将 session id 作为 cookie 传递,而不是作为“Authorisation Bearer <session_id>”http header。

There's an example in https://github.com/simple-salesforce/simple-salesforce/issues/584https://github.com/simple-salesforce/simple-salesforce/issues/584有一个例子

And one of my old answers (showing raw http but still, should give you an idea) https://stackoverflow.com/a/56162619/313628 , https://stackoverflow.com/a/57745683/313628我的一个旧答案(显示原始 http 但仍然应该给你一个想法) https://stackoverflow.com/a/56162619/313628,https ://stackoverflow.com/a/57745683/313628

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

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