python TypeError:不可哈希的类型:Django的"法令"

daolsyd0  于 2022-12-21  发布在  Python
关注(0)|答案(1)|浏览(84)

我正在做django的休息项目,我得到了一个错误,我得到了一个错误任何人都可以帮助,下面是我的代码和错误消息

class TrasactionSerializer(serializers.Serializer):
   amount = serializers.IntegerField(validators=[is_amount])
   email = serializers.EmailField()
   wallet = serializers.CharField(source='wallet.id', read_only=True)

  def validate_email(self, value):
      if CustomUser.objects.filter(email=value).exists():
          return value
      raise serializers.ValidationError({"detail": "Email not found"})

  def save(self):
    user = self.context['request'].user
    wallet = WalletModel.objects.get(user=user)
    data = self.validated_data
    url = 'https://api.paystack.co/transaction/initialize'
    headers = {
        "authorization": f"Bearer {settings.PAYSTACK_SECRET_KEY}"
    }
    r = requests.post(url, headers=headers, data=data)
    response = r.json()
    walletTransaction.objects.create(
        wallet=wallet,
        transaction_type="deposit",
        amount= data["amount"],
        paystack_payment_reference=response['data']['reference'],
        status=response["pending"],
    )

错误信息

File "/home/olaneat/Desktop/files/project/django/jobConnect/job-connect/wallet/serializers.py", line 59, in save
    headers = {
TypeError: unhashable type: 'dict'

有人能帮忙吗

pcww981p

pcww981p1#

headers = {
    {"authorization": f"Bearer {settings.PAYSTACK_SECRET_KEY}"}
}

那是一套字典,别这样
就做一本普通的字典:

headers = {
    "authorization": f"Bearer {settings.PAYSTACK_SECRET_KEY}"
}

相关问题