简体   繁体   English

Django - 'collections.OrderedDict' 对象没有属性 'headers'

[英]Django - 'collections.OrderedDict' object has no attribute 'headers'

I am getting this error on django with my dict and OrderedDict (doesnt matter which one I use).我在 django 上用我的 dict 和 OrderedDict 收到这个错误(我使用哪个无关紧要)。 I am trying to submit a CHECKSUM do paygate which I am generating with my md5 hash using the data dict.我正在尝试提交一个 CHECKSUM do paygate,我使用数据字典用我的 md5 哈希生成它。 The response I get back from paygate is the PAY_REQUEST_ID and the CHECKSUM which is regenerated with dict_ in my post_payment method.我从 paygate 得到的响应是 PAY_REQUEST_ID 和在我的 post_payment 方法中使用 dict_ 重新生成的 CHECKSUM。 I am getting the correct response as I can see my PAY_REQUEST_ID and new CHECKSUM but for some reason the 'collections.OrderedDict' object has no attribute 'headers' error pops up and I have not used 'headers' anywhere in my code.我得到了正确的响应,因为我可以看到我的 PAY_REQUEST_ID 和新的 CHECKSUM 但由于某种原因,'collections.OrderedDict' 对象没有属性 'headers' 错误弹出,我没有在我的代码中的任何地方使用 'headers'。

Can someone help in identifying what I am doing wrong.有人可以帮助确定我做错了什么。

Thanks in advance提前致谢

#just for reference i am putting 2 items in dict
response_data = OrderedDict()
data = {
        'PAYGATE_ID'    : '10011072130',
        'REFERENCE'     : 'pgtest_123456789',
       } 
CHECKSUM = calculate_md5(data)
url = 'https://secure.paygate.co.za/payweb3/initiate.trans'
data['CHECKSUM'] =  CHECKSUM
data['url'] = url
hash_valid, response_data = post_payment(data)
if not hash_valid:
    return HttpResponseForbidden('FAILED')
response_data.pop('PAYGATE_ID')
response_data.pop('REFERENCE')
return response_data


def post_payment(data):
   url = data.pop('url')
   response = requests.post(url,data=data)
   dict_ = OrderedDict()
   new = response.text.split('&')
   print(new)
   for item in new:
       list_ = item.split('=')
       key = list_[0]
       value = list_[1]
       dict_[key] = value
   is_equal, dict_['CHECKSUM'] = validate_checksum(dict_)
   return is_equal, dict_

def validate_checksum(data):
   hash_ = data.pop('CHECKSUM')
   new_hash = calculate_md5(data)
   return hash_ == new_hash, new_hash

Full Traceback完整追溯

response = get_response(request)响应 = 获取响应(请求)

AttributeError("'collections.OrderedDict' object has no attribute 'headers'") get_response AttributeError("'collections.OrderedDict' 对象没有属性 'headers'") get_response
<django.middleware.clickjacking.XFrameOptionsMiddleware object at 0x0000016523EDFF28> request <WSGIRequest: GET '/carts/checkout/'> <django.middleware.clickjacking.XFrameOptionsMiddleware 对象在 0x0000016523EDFF28> 请求 <WSGIRequest: GET '/carts/checkout/'>

response = self.process_response(request, response)响应 = self.process_response(请求,响应)

request <WSGIRequest: GET '/carts/checkout/'> response请求 <WSGIRequest: GET '/carts/checkout/'> 响应
OrderedDict([('PAY_REQUEST_ID', '9D29D540-FED8-9693-FEA1-2D6B64A5868E'), ('CHECKSUM', '097e4a83deb5f5c3840ea3e2b69e422e')]) self OrderedDict([('PAY_REQUEST_ID', '9D29D540-FED8-9693-FEA1-2D6B64A5868E'), ('CHECKSUM', '097e4a83deb5f5c3840ea3e2b69e')self422e
<django.middleware.clickjacking.XFrameOptionsMiddleware object at 0x0000026DCA93FEB8> <django.middleware.clickjacking.XFrameOptionsMiddleware 对象在 0x0000026DCA93FEB8>

Removed 'return resonse_data' and solved that error.删除了 'return resonse_data' 并解决了该错误。

CHECKSUM = calculate_md5(data)
url = 'https://secure.paygate.co.za/payweb3/initiate.trans'
data['CHECKSUM'] =  CHECKSUM
data['url'] = url
hash_valid, response_data = post_payment(data)
if not hash_valid:
    return HttpResponseForbidden('FAILED')
response_data.pop('PAYGATE_ID')
response_data.pop('REFERENCE')

暂无
暂无

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

相关问题 Django AttributeError: &#39;collections.OrderedDict&#39; 对象没有属性 &#39;pk&#39; - Django AttributeError: 'collections.OrderedDict' object has no attribute 'pk' &#39;collections.OrderedDict&#39; 对象没有属性 &#39;pk&#39; - django rest 框架 - 'collections.OrderedDict' object has no attribute 'pk' - django rest framework Django - AttributeError: 'collections.OrderedDict' 对象没有属性 'id' - Django - AttributeError: 'collections.OrderedDict' object has no attribute 'id' “collections.OrderedDict”对象没有属性 - 'collections.OrderedDict' object has no attribute AttributeError: &#39;collections.OrderedDict&#39; 对象没有属性 &#39;split&#39; - AttributeError: 'collections.OrderedDict' object has no attribute 'split' AttributeError: &#39;collections.OrderedDict&#39; 对象没有属性 &#39;iloc&#39; - AttributeError: 'collections.OrderedDict' object has no attribute 'iloc' AttributeError: 'collections.OrderedDict' object 没有属性 'value_counts' - AttributeError: 'collections.OrderedDict' object has no attribute 'value_counts' 预训练的 model 错误? 'collections.OrderedDict' object 没有属性 'eval' - pretrained model error ? 'collections.OrderedDict' object has no attribute 'eval' AttributeError: 'collections.OrderedDict' object 没有属性 'train' - AttributeError: 'collections.OrderedDict' object has no attribute 'train' Django:'collections.OrderedDict' object 不可调用 - Django : 'collections.OrderedDict' object is not callable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM