【发布时间】:2017-01-04 14:17:42
【问题描述】:
我不知道该怎么做。基本上一个特定的 API 要求
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
但他们希望表单数据是这样的:
stockLevels=[
{
"SKU": "sample string 1",
"LocationId": "de0f1890-0c49-4834-b8cd-8b766fba496a",
"Level": 3
},
{
"SKU": "sample string 1",
"LocationId": "de0f1890-0c49-4834-b8cd-8b766fba496a",
"Level": 3
}
]
我正在做的是这样的:
def change_stock_quantity(self, SKU, qty):
# Note that this will change quantity of just one item
# instead of two like in the example above
payload = {
'stockLevels':[{
'SKU': SKU,
'LocationId': self.ebay1_location_id,
'Level': qty,
}]
}
r = self.session.post(self.session_server + '//api/Stock/SetStockLevel',
data=payload)
print r.request.body
# stockLevels=SKU&stockLevels=LocationId&stockLevels=Level
# this is not correct, it should be something like:
# stockLevels:[{"SKU":"P01", "LocationId":"00000000", "Level":4}]
print r
# <Response [400]> (obivously)
关于我做错了什么有什么想法吗?
【问题讨论】:
-
获得相关 API 文档的链接?编辑:是这个吗? apps.linnworks.net/Api/Method/Stock-SetStockLevel 如果是这样,示例可能是错误的,即他们实际上期望 JSON 正文。试试原始的,例如使用 CURL,看看哪些组合有效。
-
我实际上解决了它,并将在下面发布回复。他们确实期待
x-www-form-urlencoded。 -
酷,我也同时做了一些研究 :)
标签: python json python-requests