簡體   English   中英

Django - 'collections.OrderedDict' 對象沒有屬性 'headers'

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

我在 django 上用我的 dict 和 OrderedDict 收到這個錯誤(我使用哪個無關緊要)。 我正在嘗試提交一個 CHECKSUM do paygate,我使用數據字典用我的 md5 哈希生成它。 我從 paygate 得到的響應是 PAY_REQUEST_ID 和在我的 post_payment 方法中使用 dict_ 重新生成的 CHECKSUM。 我得到了正確的響應,因為我可以看到我的 PAY_REQUEST_ID 和新的 CHECKSUM 但由於某種原因,'collections.OrderedDict' 對象沒有屬性 'headers' 錯誤彈出,我沒有在我的代碼中的任何地方使用 'headers'。

有人可以幫助確定我做錯了什么。

提前致謝

#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

完整追溯

響應 = 獲取響應(請求)

AttributeError("'collections.OrderedDict' 對象沒有屬性 'headers'") get_response
<django.middleware.clickjacking.XFrameOptionsMiddleware 對象在 0x0000016523EDFF28> 請求 <WSGIRequest: GET '/carts/checkout/'>

響應 = self.process_response(請求,響應)

請求 <WSGIRequest: GET '/carts/checkout/'> 響應
OrderedDict([('PAY_REQUEST_ID', '9D29D540-FED8-9693-FEA1-2D6B64A5868E'), ('CHECKSUM', '097e4a83deb5f5c3840ea3e2b69e')self422e
<django.middleware.clickjacking.XFrameOptionsMiddleware 對象在 0x0000026DCA93FEB8>

刪除了 '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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM