我正在做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'
有人能帮忙吗
1条答案
按热度按时间pcww981p1#
那是一套字典,别这样
就做一本普通的字典: