django - Tastypie api working with postman but not with python requests -
i have tastypie api api key authentication.
its working both ways request, post request, not working.
url = http://localhost:8000/api/path/?api_key=key&username=username
in view, when tried print request.user, regular/real user when request comes postman. python requests, anonymous user.
with python requests, doing this:
url = http://localhost:8000/api/path/?api_key=key&username=username d = {"some": "data"} r = requests.post(url, data=json.dumps(d), headers={"content-type": "application/json"})
code provided postman:
post /api/v1/abc/?api_key=somekey&username=something http/1.1 host: localhost:8000 content-type: application/json cache-control: no-cache postman-token: {"something":"something"}
please let me know questions.
my resource api authentication not working:
class userresource(modelresource): class meta: queryset = user.objects.all() fields = ['username', 'email', 'first_name', 'last_name'] resource_name = 'user' authentication = apikeyauthentication()
make sure not using sessionauthentication
or have enforce_csrf
enabled in authentication. since postman sends browser cookies request too, might reason different behaviour getting.
if case, means api authentication not working. since postman using sessionauthentication, works. ensure have added tastypie in installed_apps , created/stored api key in database.
Comments
Post a Comment