0

私はpythonhttplibを使用して、Djangotastypieに接続するためのRESTAPIを実装しました。しかし、ステータスコードを取得しようとすると、次のエラーが表示されます

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

私のコードは以下になります

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
4

1 に答える 1

5

httplib.HttpResponseではなく、django.http.HttpResponseを返す必要があります

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

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

于 2012-07-30T11:42:14.670 に答える