1

I am trying to access the Magento Rest api from Python. But at the last stage i am getting the {'messages': {'error': [{'message': 'Access denied', 'code': 403}]}}.

But, the when i tried to access the same thing from PHP script it is working fine for me.So, there is no issue with the admin role and permission.

One solution is here, but it suggest to give all the roles to guest. Which can not be happen in my case as it will be open for all the user to fetch the product from browser.

Could any one please suggest what can be the reason for not getting access the same Rest API from python but works fine with PHP.

This is my code for Python script

{AGENTO_HOST = 'http://127.0.0.1'
MAGENTO_API_BASE = '%s/api/rest/' % MAGENTO_HOST

magento = OAuth1Service(
    name               = 'magento',
    consumer_key       = 'vygdq11yzaectqwbpn1h4zwlamsrpomi',
    consumer_secret    = '5x5idvqc8rh4vc8lrxeg4hvple0u63dt',
    request_token_url  = '%s/oauth/initiate' % MAGENTO_HOST,
    access_token_url   = '%s/oauth/token' % MAGENTO_HOST,
    # Customer authorization
    #authorize_url     = '%s/oauth/authorize' % MAGENTO_HOST,
    # Admin authorize url depending on admin url
    authorize_url      = '%s/admin/oauth_authorize' % MAGENTO_HOST,
    base_url           = MAGENTO_API_BASE
)

# get request token
request_token, request_token_secret = magento.get_request_token(method='POST', params={'oauth_callback': 'oob'})

# authorize us
authorize_url = magento.get_authorize_url(request_token)

print 'Visit this URL in your browser: ' + authorize_url
code = raw_input('Paste Code from browser: ')

session = magento.get_auth_session(request_token,
                                   request_token_secret,
                                   method='POST',
                                   data={'oauth_verifier': code})

headers = {'Accept': 'application/json'}
r = session.get('products', headers=headers)

articles = r.json()}

Any help will really be appreciated.

1
  • 1
    Do you recall how you finally resolved this? Nov 4, 2015 at 17:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.