python - 在Python代码中传递auth参数

标签 python magento

我通过高级休息客户端访问 Magento url,并传递一些身份验证参数,例如:consumer_key、c​​onsumer_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/

相关文章:

php - Magento:在外部页面上加载评论表单

python - HTTP 错误 400 : Bad Request (urllib)

python - TkInter 在文件名模式匹配中插入虚假通配符

python - Python 中奇怪的内存错误

mysql - Magento 重新索引类别平面数据不起作用

magento - 无法在Magento CE 1.9中编译rwd skin SCSS

php - 如何在 PHP/Magento 中捕获这个低级别的 MySQL(?)错误

python - 查询 Pelican 主题中的特定文章(通过标签/类别)

python - cv2 destroyWindow() 在ros回调函数中不起作用

api - Magento Soap 错误 - 标签定义第 2 行中的数据过早结束