我通过高级休息客户端访问 Magento url,并传递一些身份验证参数,例如:consumer_key、consumer_secret、访问 token 和访问 secret token 。签名方法和随机数是自动存在的。我想通过 python 来获得相同的响应。请求类型为 GET。如何用Python代码传递这些参数?
最佳答案
我正在使用 Requests library 从 python 访问 Magento REST API和 requests_oauthlib .
大致是这样的:
import requests
from requests_oauthlib import OAuth1
def make_get_request(path, params):
"""Make a GET request to the Magento API."""
client_key = 'Your Client Key'
client_secret = 'Your Client Secret'
resource_owner_key = 'Your Resource Owner Key'
resource_owner_secret = 'Your Resource Owner Secret'
auth = OAuth1(client_key,
client_secret,
resource_owner_key,
resource_owner_secret)
res = requests.get(url=path, params=params, auth=auth)
return res.json()
关于python - 在Python代码中传递auth参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33389231/