Tuesday, February 25, 2020

Re: Django Session KeyError

Hi, 

please post the output of debugging the above, print after and before in these views and also check is something else is working using request.session. 
@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')
            print(dataset.to_json(orient='values'))
            request.session['ts_dataset_copy'] = dataset.to_json(orient='values')
            print(request.session['ts_dataset_copy'])
            return HttpResponse(dataset.to_json(orient='values'))
Post output of this plus the below one
def cv_classification(request, kfolds, dissimilarity_func, windows_length=0, noisy_law="", mu=0,std=0):
            noisy_law 
= noisy_law.lower()
            print(request.session['ts_dataset_copy'])
            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)

On Tuesday, 25 February 2020 03:47:25 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/ee6dd1d1-9567-46ba-a699-500d1e950788%40googlegroups.com.

No comments:

Post a Comment