问题
When passing values as parameters in the request it works:
curl "http://localhost:8080/wordgame/api/v1/rounds/?username=test_user&api_key=12345678907a9cb56b7290223165e0a7c23623df&format=json"
However, it does not work when I try to pass the values in as headers. This results in a 401:
curl -H "Authorization: ApiKey test_user:12345678907a9cb56b7290223165e0a7c23623df" -H "Accept: application/json" http://localhost:8080/wordgame/api/v1/rounds/
I am using Tastypie ApiKeyAuthentication
回答1:
Your header looks correct assuming the username/key are right..
Try the version from the github master branch, the one that pip installed from PyPI wouldn't accept the authorization header for me either.
I did this:
pip install https://github.com/toastdriven/django-tastypie/tarball/master --upgrade
回答2:
Sorry to add what is pretty much a duplicate answer but I can't comment yet. I had the same issue and as mentioned by the other answer I had to update to the latest code to get this to work since it was added after the current release.
One thing to note is that by default the documentation on readthedocs seems to track the latest development version rather than a specific release. To change this you can click on the "brought to you be read the docs" image at the bottom of the screen and select the version you are using.
来源:https://stackoverflow.com/questions/11701212/how-do-i-set-the-authorization-header-for-tastypie