1

I have used python httplib to implement REST api to connect with Django tastypie. But whenever i try to get the status code it is showing following error

AttributeError at /actions/login
HTTPResponse instance has no attribute 'status_code'

My code goes below

import hashlib
import hmac
from django.shortcuts import render_to_response
from django.template import RequestContext

def loginAction(request):
    username=request.POST['email']
    password=request.POST['password']
    import httplib, urllib
    params = urllib.urlencode({'username': username})
    #hash username here to authenticate
    digest=hmac.new("qnscAdgRlkIhAUPY44oiexBKtQbGY0orf7OV1I50", str(request.POST['password']),hashlib.sha1).hexdigest()
    auth=username+":"+digest
    headers = {"Content-type": "application/json","Accept": "text/plain","Authorization":auth}
    conn = httplib.HTTPConnection("localhost",8000)
    conn.request("POST", "/api/ecp/profile/", params, headers)
    conn.set_debuglevel(1)
    response = conn.getresponse()
    return response

1 Answer 1

5

You must return a django.http.HttpResponse, not a httplib.HttpResponse

See: (httplib) http://docs.python.org/library/httplib.html#httplib.HTTPResponse

and: (django) https://docs.djangoproject.com/en/dev/ref/request-response/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.