【发布时间】:2017-03-27 02:51:52
【问题描述】:
我正在从 API 下载数据但收到错误 401: 我了解错误 401,但不知道我的代码有什么问题。
import json
import requests
path='C:/Users/sharm_000/Desktop/Price Comparison/'
cat=str('https://affiliate-api.flipkart.net/affiliate/api/swapnilsh5.json')
r = requests.get(cat, auth=('swapnilsh5', '7018e1141bcd4ace9c3fe12277924035'))
print (r)
上面的代码返回 201 响应很好,但是当我进行下一级数据下载时,挑战就来了
link='https://affiliate-api.flipkart.net/affiliate/1.0/feeds/swapnilsh5/category/j9e-abm-c54.json?expiresAt=1479062969473&sig=1ef27c056140e0ff7cac143670584e9d&inStock=1'
r = requests.get(str(link), auth=('swapnilsh5', '7018e1141bcd4ace9c3fe12277924035'))
print(r)
这返回 401 错误,我无法弄清楚,当我使用 curl 运行上述链接时
curl -H "Fk-Affiliate-Id:swapnilsh5" -H "Fk-Affiliate-Token:7018e1141bcd4ace9c3fe12277924035" "https://affiliate-api.flipkart.net/affiliate/1.0/feeds/swapnilsh5/category/j9e-abm-c54.json?expiresAt=1479062969473&sig=1ef27c056140e0ff7cac143670584e9d&inStock=1" -o "C:\Users\sharm_000\Desktop\Price Comparison\a1c.json"
curl 命令运行良好。
请建议我哪里出错了,以及在 python 中执行相同任务的其他方法。
提前致谢。
【问题讨论】:
标签: python api curl python-requests