Python SAP cloud identity login

160 Views Asked by At

I'm trying to automate some tasks with webscraping/post/etc and can't seem to figure out how to authenticate against a SAP endpoint, using python. The endpoint is https://ar2svx3jx.accounts.ondemand.com/, I'm trying to use beautifulsoup and requests in order to authenticate so that I can login into the site replicate tasks but I keep coming short. I've tried multiple variants of python, the latest, after deleting a bunch, is below.

#!/usr/bin/env python3

import requests
from bs4 import BeautifulSoup as bSoup
import argparse
import mechanize




class Calls:
    def __init__(self, filepath):
        with open(filepath, 'r') as rf:
            endpoint_list = rf.readlines()
            rf.close()

        payload = {
            "j_username": "the_username",
            "j_password": "the_password"
        }

        for endpoint in endpoint_list:
            r = requests.post(endpoint, allow_redirects=True)

            # print(r.url)
            # print(r.content)
            print(r.headers)
            print(r.request.headers)


    #     self.get_pages(endpoint_list)
    #
    # def soup_connection(self, page):
    #     soup = bSoup(page, 'html.parser')
    #     print(soup.prettify())
    #
    # def get_pages(self, endpoints):
    #     for endpoint in endpoints:
    #         return_page = requests.get(endpoint)
    #
    #         if return_page.status_code == 200:
    #             self.soup_connection(return_page.content)
    #         else:
    #             print('Unexpected status code:', return_page.status_code)


def main():
    try:
        parser = argparse.ArgumentParser(
            description='automated testing script')
        parser.add_argument('-f', metavar='file', type=str, help='path to files with endpoints')

        args = parser.parse_args()
        file_location = args.f or 'endpoints.txt'
        Calls(file_location)

    except FileNotFoundError as e:
        print('Error: %s' % e)


if __name__ == '__main__':
    main()```
0

There are 0 best solutions below