DEV Community

Cover image for How to use Python automatically get the Sap BO Temporary License keys?
Luca Liu
Luca Liu

Posted on • Edited on

How to use Python automatically get the Sap BO Temporary License keys?

What is a Sap Temporary License Keys?

An SAP temporary license key is a license used to activate SAP software that can only be used for a limited period of time. These keys can be used for evaluation purposes or during a system migration. They are temporary solutions and usually expire after a certain period of time.

How to get the Sap BO Temporary License keys?

Temporary keys: The SAP Support Portal provides temporary Business Objects license keys in case of any error while creating a permanent license key. You can download these keys by logging on to the link www.service.sap.com/licensekey on the Support Portal and selecting the "Get Temporary License Key" link. These temporary license keys are valid for a maximum of 90 days.

Method 1: Manual download

  1. www.service.sap.com/licensekey Open the URL and click here to download a file called "bobj-temp-license-key.zip":

Image description

  1. After unzipping there is a pdf file named "SAP Analytics Emergency License Key Process", in which you can find the License Key you need.

Image description

Method 2: Automate the process of getting Sap Temporary keys using Python

Download bobj-temp-license-key.zip

You can use the requests library to download the zip file directly and save it in a specific path.

import requests
import os

# Define the URL of the zip file
zip_file_url = 'https://support.sap.com/content/dam/support/en_us/library/ssp/my-support/keys/bobj-temp-license-key.zip'

# Define the folder path where you want to save the zip file.
download_zip_path = r"C:\\Users\\USERNAME\\Projects\\download_zip"

# Ensure the download folder exists
os.makedirs(download_zip_path, exist_ok=True)

# Create the full path for the zip file
zip_file_path = os.path.join(download_zip_path, 'bobj-temp-license-key.zip')

# Send a GET request to the URL and save the content to the zip file
response = requests.get(zip_file_url, stream=True)
with open(zip_file_path, 'wb') as zip_file:
    for chunk in response.iter_content(chunk_size=128):
        zip_file.write(chunk)

print(f"Zip file downloaded to: {zip_file_path}")
Enter fullscreen mode Exit fullscreen mode

Unzip the zip file to get the pdf

The SAP Temporary Keys are saved in the PDF file, which you need to extract from the zip file first. You can use zipfile to obtain the information.

import zipfile

# zip the zip file into 'bobj-temp-license-key'
file_path_zip = r"{}/bobj-temp-license-key.zip".format(download_zip_path)

if os.path.exists(file_path_zip):
    zip_file = zipfile.ZipFile(file_path_zip)
    zip_file.extractall(keys_path)
    zip_file.close()

# you can get the path of the pdf after unzip
file_path_pdf = "..."
Enter fullscreen mode Exit fullscreen mode

Get the required Licence Key from the pdf file.

Take SAP BusinessObjects Tempory Licence Key as an example, the Licence Key is located on the second page of the pdf after the "CPU 4.2" field, after testing to determine the SAP BusinessObjects Tempory Licence Key, the Licence Key is located on the second page of the pdf after the "CPU 4.2" field, after testing to determine the SAP BusinessObjects Tempory Licence Key. The Licence Key is located after the "CPU 4.2" field on the second page of the pdf:

import PyPDF2
import os

# Get SAP BusinessObjects Tempory Licence Key
def get_key_from_text(text):
    start = text.find('CPU 4.2') + 8
    return text[start:start + 32]

# file_path_pdf is the path of the pdf in the previous step 
if os.path.exists(file_path_pdf):
    pdf_file = open(file_path_pdf, 'rb')
    pdf_reader = PyPDF2.PdfReader(pdf_file)
    page = pdf_reader.pages[1]
    text = page.extract_text()
    latest_key = get_key_from_text(text)
    pdf_file.close()
Enter fullscreen mode Exit fullscreen mode

Automate Updating Process

If you need to update the license key every 90 days, you can save the license key in a txt file and compare it with the locally saved license key after you successfully get the latest license key, if latest_key ! If latest_key != current_key, then replace latest_key with current_key to ensure that the latest license key is always saved in the txt file.

if os.path.exists(file_path_pdf):
    pdf_file = open(file_path_pdf, 'rb')
    pdf_reader = PyPDF2.PdfReader(pdf_file)
    page = pdf_reader.pages[1]
    text = page.extract_text()
    latest_key = get_key_from_text(text)
    pdf_file.close()
    if latest_key != current_key:
        with open(current_key_txt_path, 'w') as file:
            file.write(latest_key)
        print("license updated, latest license", latest_key)
    else:
        print("license didn't update, current license:", latest_key)
else:
    print("PDF is not exists")

Enter fullscreen mode Exit fullscreen mode

Explore more

Thank you for taking the time to explore data-related insights with me. I appreciate your engagement.

šŸš€ Connect with me on LinkedIn

šŸŽƒ Connect with me on X

šŸŒ Connect with me on Instagram

Top comments (0)