Link to home
Start Free TrialLog in
Avatar of Kobus Smit
Kobus Smit

asked on

Python Call SAP RFC

Hi.

I am want to code a python program to connect to SAP. I use the PyRFC library.

With the following code:
from pyrfc import Connection

Open in new window


I am getting the error:
ImportError                               Traceback (most recent call last)
<ipython-input-14-c21fcdc26a13> in <module>()
----> 1 from pyrfc import Connection

ImportError: cannot import name 'Connection'
Avatar of dfke
dfke

Hi,

First make sure that your variable indeed is 'Connection'. If so then maybe it loops because of a dead reference and you need to re-position your 'from pyrfc import Connection' to the end.

For instance:

x.py:

from test.y import y2

def x1():
    print('x1')
    y2()

Open in new window


y.py:

from test.x import x1

def y1():
    print('y1')
    x1()

def y2():
    print('y2')

if __name__ == '__main__':
    y1()

Open in new window


The result will then be:  ImportError: cannot import name 'x1'

But if re positioned in X like below:

def x1():
    print('x1')
    y2()

from test.y import y2

Open in new window


The output will be:

y1
x1
y2

Open in new window


Cheers
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.