[Python] Python script causing An exception occurred while connecting with SAP system:...

Discussão em 'Python' iniciado por Stack, Fevereiro 14, 2025.

  1. Stack

    Stack Membro Participativo

    Here is my python script that tries to pull data from a SAP table into AWS Glue.

    from pyrfc import Connection
    import pandas as pd
    ## Variables
    sap_table = 'TABLENAME' # SAP Table Name
    fields = ["FIELD1", "FIELD2"] # List of fields
    options = [""]
    max_rows = 10
    from_row = 0
    try:
    # Establish SAP RFC connection
    conn = Connection(ashost='mysapserver.com', sysnr='00', client='000', user='username', passwd='password')
    print(f"SAP Connection successful – connection object: {conn}")
    if conn:
    # Read SAP Table information
    tables = conn.call("RFC_READ_TABLE", QUERY_TABLE=sap_table, DELIMITER='|', FIELDS=fields, OPTIONS=options, ROWCOUNT=max_rows, ROWSKIPS=from_row)
    # Access specific row & column information from the SAP Data
    data = tables["DATA"] # pull the data part of the result set
    columns = tables["FIELDS"] # pull the field name part of the result set
    df = pd.DataFrame(data, columns = columns)
    if df:
    print(f"Successfully extracted data from SAP using custom RFC - Printing the top 5 rows: {df.head(5)}")
    else:
    print("No data returned from the request. Please check database/schema details")
    else:
    print("Unable to connect with SAP. Please check connection details")
    except Exception as e:
    print(f"An exception occurred while connecting with SAP system: {e.args}")


    This results in the following error:


    An exception occurred while connecting with SAP system: ("unhashable type: 'dict'",)
    ​

    Traceback (most recent call last): File "<string>", line 19, in <module> File "/usr/local/lib64/python3.11/site-packages/pandas/core/frame.py", line 851, in init

    It successfully connects so I am thinking it is the syntax around the table, field names.

    Continue reading...

Compartilhe esta Página