我使用Facebook创建了一个REST API来注册:

  • Django 1.7

  • Python Social Auth 0.2.12

  • Tastypie

当我在Web视图中使用PSA时,它可以正常工作 . 但我尝试请求API我收到此错误:

/ api / v1 / social_sign_up /上的AttributeError'响应'对象没有属性'has_header'请求方法:POST请求URL:http://dev.midiacode.com:8000 / api / v1 / social_sign_up / Django版本:1.7 . 4异常类型:AttributeError异常值:'Response'对象没有属性'has_header'异常位置:/home/vagrant/.virtualenvs/midiacode_dj1.7/local/lib/python2.7/site-packages/django/utils/cache .py在patch_vary_headers中,第148行Python可执行文件:/home/vagrant/.virtualenvs/midiacode_dj1.7/bin/python Python版本:2.7.5 Python路径:['/ var / www / midiacode-api','/ home / vagrant / .virtualenvs / midiacode_dj1.7 / lib / python2.7','/ home / vagrant / .virtualenvs / midiacode_dj1.7 / lib / python2.7 /plat-x86_64-linux-nuu','/ home / vagrant / .virtualenvs / midiacode_dj1.7 / lib / python2.7 / lib-tk','/ home / vagrant / .virtualenvs / midiacode_dj1.7 / lib / python2.7 / lib -old','/ home / vagrant / .virtualenvs /midiacode_dj1.7/lib/python2.7/lib-dynload','/ usr / lib / python2.7','/ usr / lib / python2.7 / plat-x86_64-linux-gnu','/ usr / lib / python2.7 / lib-tk','/ home / vagrant / .virtualenvs / midiacode_dj1.7 / local / lib / python2.7 / site-package']服务器时间:2015年9月18日星期五19:30 :34 0000

我的请求是:POST {} / social_sign_up /

{
"provider":"facebook",   
"access_token":"CAAXAb1l2Bh4BAIxPoQYsz6BaWLl0muRLKHCycVhsYZAsd8ZB9TzsTcvsn5OtZCWe4N2bV2UYK4nLGy9VWA7JjhSmii3nfkZAkgphZAKypyYCcx9TQeGoWgIV7wuBj5HDyAmdregMztOub3Huzh5MYBAGxsZBwBQhJI1PC3I7M92VbWTiVvvKhfJQ9EYyPw4pqBUfTBwjpXhwZDZD"
}

我的资源:

class SocialSignUpResource(BaseModelResource):

class Meta:
    queryset = MidiacodeUser.objects.all()
    allowed_methods = ['post']
    resource_name = "social_sign_up"
    always_return_data = True
    authentication = AnonymousAuthentication()
    authorization = Authorization()

def obj_create(self, bundle, request=None, **kwargs):
    provider = bundle.data['provider']
    access_token = bundle.data['access_token']
    strategy = load_strategy(request)
    uri = redirect_uri = "social:complete"
    if uri and not uri.startswith('/'):
        uri = reverse(redirect_uri, args=(provider,))
    backend = load_backend(strategy, provider, uri)
    user = backend.do_auth(access_token=access_token)
    if user and user.is_active:
        bundle.obj = user
        print bundle
        return bundle
    else:
        print "no user"
        raise HttpBadRequest("Error authenticating user with this provider")