简体   繁体   中英

AttributeError: 'module' object has no attribute 'postDirectOrder'

I'm trying to use this python package https://pypi.python.org/pypi/pesapal in one of my projects.

But I noticed that for some weird reason the author stuffed all the logic in the __init__.py file which doesn't make sense to me, but hey..

So when I try to use the package I get the following error:

'module' object has no attribute 'postDirectOrder

I'm on Python 2.7.7, I've tried from pesapal import * but no luck. I tried:

>>> from pesapal import PesaPal
>>> url = PesaPal.postDirectOrder(post_params, request_data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unbound method postDirectOrder() must be called with PesaPal instance as first argument (got dict inst
ance instead)

The 0.3 release differs significantly from later code; it contains a class PesaPal() which takes consumer_key and consumer_secret arguments:

pp = PesaPal(key, secret)
url = pp.postDirectOrder(post_params, request_data)

The project never correctly tagged the 0.3 release, but there is a 0.3 release commit ; you can browse the source tree at that commit to get an idea of what is expected.

The project README there includes an example:

 import pesapal, urllib2 consumer_key ='consumer_key' consumer_secret = 'consumer_secret' testing = False ### make client client = pesapal.PesaPal(consumer_key, consumer_secret, testing) ### post a direct order request_data = { 'Amount': '', 'Description': '', 'Type': '', 'Reference': '', 'PhoneNumber': '' } post_params = { 'oauth_callback': 'www.example.com/post_payment_page' } request = client.postDirectOrder(post_params, request_data) # get url to display as an iframe print request.to_url() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM