Closed jleefresh closed 2 years ago
Hi @jleefresh,
Thanks for opening the issue.
Could you please provide a simple code sample to reproduce the issue?
Thanks!
import requests
from requests.auth import AuthBase
import oauth1.authenticationutils as authenticationutils
from oauth1.signer import OAuthSigner
KEY_FILE = 'signing-key.p12'
KEY_PASS = '<REDACTED>'
CONSUMER_KEY = '<REDACTED>'
ICA = '<REDACTED>'
class MCSigner(AuthBase):
def __init__(self, consumer_key, signing_key):
self.signer = OAuthSigner(consumer_key, signing_key)
def __call__(self, request):
self.signer.sign_request(request.url, request)
return request
signing_key = authenticationutils.load_signing_key(KEY_FILE, KEY_PASS)
signer = MCSigner(CONSUMER_KEY, signing_key)
resp = requests.get(
f'https://sandbox.api.mastercard.com/track/bps/supplier-payment-agents/{ICA}/suppliers',
auth=signer
)
This produces the aforementioned error.
Thanks, @jleefresh for sharing the code sample.
The AttributeError
is thrown by the OAuthSigner.sign_request
function because it is expecting a Request object instead of a PreparedRequest.
We are going to update the function to work with both types and release a new version of the library. In the meantime, you could sign the requests with the supported Request object as documented in the README or by using the OAuth1RSA helper (see: https://github.com/Mastercard/oauth1-signer-python#usage-of-the-oauth_ext).
Bug Report Checklist
Description OAuthSigner fails with the following error:
To Reproduce Use OAuthSigner
Suggest a fix/enhancement https://github.com/Mastercard/oauth1-signer-python/blob/main/oauth1/signer.py#L39 uses
request.data
when it should berequest.body
Tested on python 3.9 w/ python requests v2.27.1