我有一个magento 1.9.1社区实例设置,我正在尝试通过REST API访问它们。我能够对产品/客户等执行GET请求,但是在使用POST请求添加产品时我遇到了困难。我的示例代码如下。我哪里错了?
from requests_oauthlib import OAuth1 as OAuth
import requests
import json
oauth = OAuth(client_key=consumer_key,
client_secret=consumer_secret,
resource_owner_key=access_key,
resource_owner_secret=access_secret)
headers = {'Content-Type': 'application/json',
'Accept': 'application/json'}
product = """{
“type_id”:“简单”, “attribute_set_id”:“4”, “sku”:“测试”, “名字”:“测试”, “价格”:“100”, “description”:“随机描述”, “short_description”:“随机”, “重量”:“500”, “状态”:“1”, “能见度”:“4”, “tax_class_id”:“2” } “”“
payload = json.loads(product)
uri = "http://magentohost/api/rest/products"
r = requests.post(url=uri, data=json.dumps(payload),headers=headers, auth=oauth)
print r