Monday, February 24, 2020

Re: Django Session KeyError

Make sure your line request.session['ts_dataset_copy'], print anything above it, also make sure you are using POST method in forms (method = "post") 

On Tuesday, February 25, 2020 at 3:47:25 AM UTC+5:30, Guy NANA wrote:
I have an angular frontend app which send file to django backend which data is setting in django session. After I send a httprequest to django backend to make ML tratements on that data and get the results. But I've a 500 sever error: keyerror 'ts_dataset_copy': KeyError: 'ts_dataset_copy'
[24/Feb/2020 18:43:46] "GET /cv_classification/5/FOTS/283/None/0/0 HTTP/1.1" 500 78264. Here are my django code:

Firstly I upload timeseries dataset file from angular frontend (All thing is ok)   
@csrf_exempt
   
def upload_local_dataset(request):
       
if request.method == 'POST':
            dataset
= pd.read_csv(request.FILES.get('datasetfilepath'), header=None, index_col=None)
            request
.session['ts_datset'] = dataset.to_json(orient='values')
            request
.session['ts_dataset_copy'] = dataset.to_json(orient='values')
   
           
return HttpResponse(dataset.to_json(orient='values'))



# second httrequest that throws a server internal error

    def cv_classification(request, kfolds, dissimilarity_func, windows_length=0, noisy_law="", mu=0,
   
        std
=0):
            noisy_law
= noisy_law.lower()
            df
= pd.read_json(request.session['ts_dataset_copy'], orient='values')
            predictions
= cv_classify(df, kfolds, dissimilarity_func, windows_length, noisy_law, mu, std)
           
return JsonResponse(predictions, safe=False)



Thanks for your help!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1822d7cf-442d-4f9d-83ea-9037e8a98408%40googlegroups.com.

No comments:

Post a Comment