Android 通过改造2.0调用api时出现内部服务器错误

Android 通过改造2.0调用api时出现内部服务器错误,android,django,python-3.x,retrofit2,Android,Django,Python 3.x,Retrofit2,这里的“获取”请求(学生列表)工作得很好,但当我执行“发布”请求(冲压)时,它不工作,但通过邮递员工作 这是我的api接口 public interface AuthApi { @FormUrlEncoded @POST("students/") Call<Person> punch( @Field("name") String code, @Field("mobile") String mobile

这里的“获取”请求(学生列表)工作得很好,但当我执行“发布”请求(冲压)时,它不工作,但通过邮递员工作

这是我的api接口

    public interface AuthApi {


    @FormUrlEncoded
    @POST("students/")
    Call<Person> punch(
            @Field("name") String code,
            @Field("mobile") String mobile,
            @Field("time") String time,
            @Field("late") String late
            );
    @GET("students/")
    Call<List<Person>> studentlist();
}
这是django(服务器)端的回溯


如果您要在“邮递员入体请求”中发送数据,请尝试此解决方案:

制作一个这样的类:

public class PunchRequest {
    private String code;
    private String mobile;
    private String time;
    private String late;

    public punch(String code, String mobile, String time, String late) {
        this.code = code;
        this.mobile = mobile;
        this.time = time;
        this.late = late;
    }
}
并通过以下方式更改您的服务:

@FormUrlEncoded
@POST("students/")
Call<Person> punch( @Body PunchRequest request));
@FormUrlEncoded
@帖子(“学生/”)
调用punch(@Body PunchRequest request));

并测试它,让我知道结果

尝试从postman调用您的api,看看它是否正常工作。从日志来看,这似乎是服务器错误。在问题中,您说您正在执行get请求,但在日志中,我看到django服务器收到了post请求。请从
考勤/student/views.py发布views.py
哪个请求不起作用?punch或studentList()?我没有看到views.py文件,也没有从服务器日志复制回溯。很难从错误html响应中获得回溯
    @csrf_exempt
def student_list(request):
    if request.method == 'GET':
        students = Student.objects.all()
        serializer = StudentSerializer(students, many=True)
        return JsonResponse(serializer.data, safe=False)

    elif request.method == 'POST':
        return JsonResponse( status=200)
    Internal Server Error: /students/
Traceback (most recent call last):
  File "/home/kethan/attendanceapi/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/kethan/attendanceapi/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/kethan/attendanceapi/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/kethan/attendanceapi/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/kethan/attendanceapi/attendance/student/views.py", line 21, in student_list
    return JsonResponse( status=200)
TypeError: __init__() missing 1 required positional argument: 'data'
[25/Jun/2017 04:09:25] "POST /students/ HTTP/1.1" 500 72196
public class PunchRequest {
    private String code;
    private String mobile;
    private String time;
    private String late;

    public punch(String code, String mobile, String time, String late) {
        this.code = code;
        this.mobile = mobile;
        this.time = time;
        this.late = late;
    }
}
@FormUrlEncoded
@POST("students/")
Call<Person> punch( @Body PunchRequest request));