繁体   English   中英

HTTPResponse实例在python / django中没有属性'status_code'

[英]HTTPResponse instance has no attribute 'status_code' in python/django

我已经使用python httplib来实现REST api以与Django tastypie连接。 但是每当我尝试获取状态代码时,它就会显示以下错误

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

您必须返回django.http.HttpResponse,而不是httplib.HttpResponse

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM