0

I am trying to call SAP web service using zeep module. We have a web service method called “-CTSH-HC_RFC_XCHG_RATE_UPLOAD” and when try to call that method, getting the error ” Service has no operation '_' “ . Since method name has hyphen, python is not considering the strings after hyphen.

message = client.service_-CTSH_-HC_RFC_XCHG_RATE_UPLOAD()

Note: We cannot change the SAP web service method name as SAP team is following the certain naming convention for method name.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Vignesh S
  • 11
  • 2
  • if this is an external python module, how exactly did it manage to define a method with a hyphen without getting an error? – N Chauhan Aug 10 '18 at 12:54
  • You should maybe show the declaration of such object. Are you sure it is written in Python? – ibarrond Aug 10 '18 at 13:05

2 Answers2

0

That's not valid python syntax. Python is parsing the code as:

client.service_ - CTSH_-HC_RFC_XCHG_RATE_UPLOAD()

I.e. subtraction of client.service_ and that function call.

You can try to use getattr instead:

method = getattr(client, "service_-CTSH_-HC_RFC_XCHG_RATE_UPLOAD")
method()   # call the method

Assuming that zeep does not "normalize" the invalid method name in some other way.


Working example:

>>> class A:
...     pass
... 
>>> setattr(A, "service_-CTSH_-HC_RFC_XCHG_RATE_UPLOAD", lambda self: print('called'))
>>> 
>>> a = A()
>>> getattr(a, "service_-CTSH_-HC_RFC_XCHG_RATE_UPLOAD")()
called
>>> method = getattr(a, "service_-CTSH_-HC_RFC_XCHG_RATE_UPLOAD")
>>> method
<bound method <lambda> of <__main__.A object at 0x7f4651c5e518>>
>>> method()
called
Giacomo Alzetta
  • 2,431
  • 6
  • 17
0

Have you tried this?

import client.service

method_called =  __import__("_-CTSH_-HC_RFC_XCHG_RATE_UPLOAD")

Reference

Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84