'を通して取得の要求を、APIの呼び出し中(student_list)は完全に正常に動作しますが、私は(パンチ)'をポストの要求を行うときには、仕事をdoen'tが、それは郵便配達を介して動作内部サーバーエラーがここに換装2.0
この
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();
}
私のAPIインタフェースであり、これは私のAPIコールである
View.OnClickListener submitListener =新しいView.OnClickListener(){
@Override
public void onClick(View v) {
if (name.getText().toString().equals("")
|| mobile.getText().toString().equals("")
|| mobile.getText().toString().length() != 10) {
Toast.makeText(MainActivity.this, "please enter correct credentials", Toast.LENGTH_SHORT).show();
} else {
date = new Date();
SimpleDateFormat localDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String time = localDateFormat.format(date);
String late="";
if (date.getHours() == 10 && date.getMinutes() > 29 && date.getSeconds() > 0) {
late=("late by: "
+ new Integer(date.getMinutes() - 30).toString() + "mins "
+ new Integer(date.getSeconds()) + "secs");
} else if (date.getHours() > 10) {
late= ("late by: "
+ new Integer(date.getHours() - 10) + "hrs "
+ new Integer(date.getMinutes()).toString() + "mins "
+ new Integer(date.getSeconds()) + "secs");
} else {
late="in time";
}
mApi = new RetrofitHelper<AuthApi>().getApi(AuthApi.class);
punchCall=mApi.punch(name.getText().toString(),mobile.getText().toString(),time,late);
punchCall.enqueue(new Callback<Person>() {
@Override
public void onResponse(Call<Person> call, Response<Person> response) {
Toast.makeText(MainActivity.this,"success",Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<Person> call, Throwable t) {
Toast.makeText(MainActivity.this,"failed",Toast.LENGTH_SHORT).show();
}
});
}
}
};
これは私のlogcat
06-24 23:51:20.079 10891-12481/com.example.kethan.project D/OkHttp: --> POST http://192.168.0.118:8000/students/ http/1.1
06-24 23:51:20.079 10891-12481/com.example.kethan.project D/OkHttp: Content-Type: application/x-www-form-urlencoded
06-24 23:51:20.080 10891-12481/com.example.kethan.project D/OkHttp: Content-Length: 105
06-24 23:51:20.080 10891-12481/com.example.kethan.project D/OkHttp: name=ket&mobile=8142142827&time=2017%2F06%2F24%2023%3A51%3A20&late=late%20by%3A%2013hrs%2051mins%2020secs
06-24 23:51:20.081 10891-12481/com.example.kethan.project D/OkHttp: --> END POST (105-byte body)
06-24 23:51:20.332 10891-12481/com.example.kethan.project D/OkHttp: <-- 500 Internal Server Error http://192.168.0.118:8000/students/ (250ms)
06-24 23:51:20.333 10891-12481/com.example.kethan.project D/OkHttp: Date: Sat, 24 Jun 2017 18:21:20 GMT
06-24 23:51:20.334 10891-12481/com.example.kethan.project D/OkHttp: Server: WSGIServer/0.2 CPython/3.5.2
06-24 23:51:20.334 10891-12481/com.example.kethan.project D/OkHttp: Vary: Cookie
06-24 23:51:20.334 10891-12481/com.example.kethan.project D/OkHttp: Content-Type: text/html
06-24 23:51:20.334 10891-12481/com.example.kethan.project D/OkHttp: Content-Length: 72215
06-24 23:51:20.334 10891-12481/com.example.kethan.project D/OkHttp: X-Frame-Options: SAMEORIGIN
06-24 23:51:20.392 10891-12481/com.example.kethan.project D/OkHttp: <!DOCTYPE html>
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: <html lang="en">
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: <head>
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: <meta http-equiv="content-type" content="text/html; charset=utf-8">
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: <meta name="robots" content="NONE,NOARCHIVE">
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: <title>TypeError at /students/</title>
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: <style type="text/css">
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: html * { padding:0; margin:0; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: body * { padding:10px 20px; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: body * * { padding:0; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: body { font:small sans-serif; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: body>div { border-bottom:1px solid #ddd; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: h1 { font-weight:normal; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: h2 { margin-bottom:.8em; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: h2 span { font-size:80%; color:#666; font-weight:normal; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: h3 { margin:1em 0 .5em 0; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: h4 { margin:0 0 .5em 0; font-weight: normal; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: code, pre { font-size: 100%; white-space: pre-wrap; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: tbody td, tbody th { vertical-align:top; padding:2px 3px; }
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: thead th {
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
06-24 23:51:20.393 10891-12481/com.example.kethan.project D/OkHttp: font-weight:normal; font-size:11px; border:1px solid #ddd;
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: table.vars { margin:5px 0 2px 40px; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: table.vars td, table.req td { font-family:monospace; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: table td.code { width:100%; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: table td.code pre { overflow:hidden; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: table.source th { color:#666; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: table.source td { font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: ul.traceback { list-style-type:none; color: #222; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: ul.traceback li.frame { padding-bottom:1em; color:#666; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: ul.traceback li.user { background-color:#e0e0e0; color:#000 }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: div.context { padding:10px 0; overflow:hidden; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: div.context ol { padding-left:30px; margin:0 10px; list-style-position: inside; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: div.context ol li { font-family:monospace; white-space:pre; color:#777; cursor:pointer; padding-left: 2px; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: div.context ol li pre { display:inline; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: div.context ol.context-line li { color:#505050; background-color:#dfdfdf; padding: 3px 2px; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: div.context ol.context-line li span { position:absolute; right:32px; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: .user div.context ol.context-line li { background-color:#bbb; color:#000; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: .user div.context ol li { color:#666; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: div.commands { margin-left: 40px; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: div.commands a { color:#555; text-decoration:none; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: .user div.commands a { color: black; }
06-24 23:51:20.394 10891-12481/com.example.kethan.project D/OkHttp: #summary { background: #ffc; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #summary h2 { font-weight: normal; color: #666; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #explanation { background:#eee; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #template, #template-not-exist { background:#f6f6f6; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #template-not-exist ul { margin: 0 0 10px 20px; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #template-not-exist .postmortem-section { margin-bottom: 3px; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #unicode-hint { background:#eee; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #traceback { background:#eee; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #requestinfo { background:#f6f6f6; padding-left:120px; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #summary table { border:none; background:transparent; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: #requestinfo h3 { margin-bottom:-1em; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: .error { background: #ffc; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: .specific { color:#cc3300; font-weight:bold; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: h2 span.commands { font-size:.7em;}
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: span.commands a:link {color:#5E5694;}
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: pre.exception_value { font-family: sans-serif; color: #666; font-size: 1.5em; margin: 10px 0 10px 0; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: .append-bottom { margin-bottom: 10px; }
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: </style>
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp:
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: <script type="text/javascript">
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: //<!--
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: function getElementsByClassName(oElm, strTagName, strClassName){
06-24 23:51:20.395 10891-12481/com.example.kethan.project D/OkHttp: // Written by Jonathan Snook, http://www.snook.ca/jon; Add-ons by Robert Nyman, http://www.robertnyman.com
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: var arrElements = (strTagName == "*" && document.all)? document.all :
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: oElm.getElementsByTagName(strTagName);
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: var arrReturnElements = new Array();
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: strClassName = strClassName.replace(/\-/g, "\\-");
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: var oElement;
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: for(var i=0; i<arrElements.length; i++){
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: oElement = arrElements[i];
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: if(oRegExp.test(oElement.className)){
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: arrReturnElements.push(oElement);
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: return (arrReturnElements)
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: function hideAll(elems) {
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: for (var e = 0; e < elems.length; e++) {
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: elems[e].style.display = 'none';
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: window.onload = function() {
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: hideAll(getElementsByClassName(document, 'table', 'vars'));
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: hideAll(getElementsByClassName(document, 'ol', 'pre-context'));
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: hideAll(getElementsByClassName(document, 'ol', 'post-context'));
06-24 23:51:20.396 10891-12481/com.example.kethan.project D/OkHttp: hideAll(getElementsByClassName(document, 'div', 'pastebin'));
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: function toggle() {
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: for (var i = 0; i < arguments.length; i++) {
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: var e = document.getElementById(arguments[i]);
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: if (e) {
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: e.style.display = e.style.display == 'none' ? 'block': 'none';
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: return false;
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: function varToggle(link, id) {
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: toggle('v' + id);
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: var s = link.getElementsByTagName('span')[0];
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: var uarr = String.fromCharCode(0x25b6);
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: var darr = String.fromCharCode(0x25bc);
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: s.textContent = s.textContent == uarr ? darr : uarr;
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: return false;
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: function switchPastebinFriendly(link) {
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: s1 = "Switch to copy-and-paste view";
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: s2 = "Switch back to interactive view";
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: link.textContent = link.textContent.trim() == s1 ? s2: s1;
06-24 23:51:20.397 10891-12481/com.example.kethan.project D/OkHttp: toggle('browserTraceback', 'pastebinTraceback');
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: return false;
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: }
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: //-->
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: </script>
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp:
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: </head>
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: <body>
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: <div id="summary">
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: <h1>TypeError at /students/</h1>
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: <pre class="exception_value">__init__() missing 1 required positional argument: 'data'</pre>
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: <table class="meta">
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: <tr>
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: <th>Request Method:</th>
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: <td>POST</td>
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: </tr>
06-24 23:51:20.398 10891-12481/com.example.kethan.project D/OkHttp: <tr>
で、これは出席/学生/ views.pyファイルである
@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)
これはtraceballジャンゴ(サーバー)からである側
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
結果について私が知っていますそれが動作していることを確認します。ログからはサーバーエラーであると私には思われます。 – Sanny
質問では、取得要求を出していると言いましたが、ログにはdjangoサーバーが投稿要求を受け取ったことがわかります。 –
'attendances/student/views.py'からviews.pyを投稿してください –