Skip to Content

Logon Token Syntax for RESTFul API Using Python in Jupyter Notebook

I have been working with Python to access the BO repository (Semantic layer, Webi, etc.) info using the RESTFul API. I am new to python and also new to using APIs, but have been using BO itself for a while. I have been able to send successful POST and GET commands using a Chrome plug-in called Talend API tester, which is really cool. Now i'm trying to convert these tests to a python script inside a Jupyter notebook that will eventually perform all sorts of cool magic tricks. When i try to apply the successful commands from the in-browser API tester to a Jupyter notebook using Python, i am getting errors related to media format. I'm guessing it's something simple.

My next step will be to use the results of the Logon Key GET command to send the subsequent POST command with the Logon but for now I just want to become more comfortable with sending basic commands to the BO repository by manually using the Logon Token.

This works fine:

Part 1
Command:

import requests
response = requests.get("http://servername:8080/biprws/logon/long")
print(response.content)

Response:b' http://www.sap.com/rws/bip"> name="password" type="string"> secEnterprise '

Part 2

When i run this though i get a 415 status code:

Command:

header = 'Content-Type: application/xml'
body = ' http://www.sap.com/rws/bip"> name="password" type="string">MyPassword secEnterprise my.username '
addy = 'http://servername:8080/biprws/logon/long'

response = requests.post(addy,header,body)

print(response)

Response:

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Jul 30, 2020 at 05:32 PM

    Additionally, here is a nice blog that uses RESTful with Python

    https://blogs.sap.com/2017/09/16/communicating-with-the-restful-web-services-via-python/

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 30, 2020 at 05:25 PM

    Hi,

    the body of your response looks like it is not well formatted xml. it should look like:

    <attrs xmlns="http://www.sap.com/rws/bip">
        <attr name="clienttype" type="string"></attr>
        <attr name="password" type="string">secret</attr>
        <attr name="auth" type="string" possibilities="secEnterprise,secLDAP,secWinAD,secSAPR3">secEnterprise</attr>
        <attr name="username" type="string">johndoe</attr>
    </attrs>
    
    

    If that is not the problem, and your error points to the media format try adding the header:

    Accept : application/xml

    Dan

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.