api - Python Requests giving response 401 -
i downloading data api getting error 401: understand error 401 dont know wrong in code.
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)
the above code returns 201 response great, challenge comes when go next level of data download
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)
this return 401 error, not able figure out, when run above link using 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"
the curl commands work absolutely fine.
please suggest going wrong , other ways of doing same task in python.
thanks in advance.
the api endpoint connecting uses non standard headers. auth not work you. have pass them custom headers, have done when using curl.
requests.get(str(link), headers = { "fk-affiliate-id" : 'swapnilsh5', "fk-affiliate-token": '7018e1141bcd4ace9c3fe12277924035'})
Comments
Post a Comment