python - 如何使用邮递员向 Django RestAPI 提供用户输入?
问题描述
我制作了一个 DjangoRestApi 并使用邮递员(POST 方法)提供用户输入。但错误是
TypeError: Object of type 'JSONDecodeError' is not JSON serializable
它显示在我出错的 django 服务器中,请帮助谢谢
视图.py
import spacy
from django.shortcuts import render,HttpResponse
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from django.http import JsonResponse
from django.core import serializers
from django.conf import settings
import json
nlp = spacy.load('en_core_web_sm')
@api_view(["POST"])
def nounphrases(requestdata):
try:
text = json.loads(requestdata.body)
nounphrases = []
for word in (nlp((text))):
c = (word.lemma_)
nounphrases.append(c)
output = [{"nounphrases" : nounphrases }]
return JsonResponse(json.dumps(output))
except ValueError as e:
return Response(e,status.HTTP_400_BAD_REQUEST)
解决方案
推荐阅读
- windows - 通过 Ansible 从 Powershell 执行 .bat 文件
- html - 尝试对齐社交媒体图标,使它们在分隔符之间完美居中
- python - 在迭代调用的函数中绘制结果被覆盖
- javascript - 如何使用排序键中的任何值查询 DynamoDB?
- django - 如何使用 manage.py 在同一目录中运行另一个 python 文件
- ios - 在共享扩展中旋转图像
- java - SOAP Web 服务消耗问题
- r - Is there a way to count occurrences of a specific value for unique columns in a dataframe in R?
- bash - 如何通过 ID 提取 HTML 标签?
- c++ - 反应任务在检测任务通知之前等待