콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5225 화면

What am i doing wrongly with api code?

Every thing works well with Postman api test but I keep having session expired each time i called get controller function on Android App.

I always get a valid session id when authenticating user on ..... https://127.0.0.1/web/session/authenticate

I need guide please.

### My Code Below:###

from odoo import http

from odoo.http import request


class FieldWorker(http.Controller):
# Update Controller

@http.route('/update_worker', type='json', auth='user')

def update_worker(self, **rec):

    if request.jsonrequest:

        if rec['id']:

            fieldworker = request.env['field.workers'].search([('id', '=', rec['id'])])

            if fieldworker:

                fieldworker.write(rec)

            args = {'success': True, 'message': 'Fieldworker Updated'}

    return args


# Get Controller

@http.route('/get_fieldworkers', type='json', auth='user')

def get_fieldworkers(self):

    fieldworker_rec = request.env['field.workers'].search([])

    fieldworkers = []

        for rec in fieldworker_rec:

            vals = {

                'id': rec.id,

                'name': rec.name,

                'community': rec.community,

                'latitudes': rec.latitudes,

                'longitudes': rec.longitudes,

                'team_ids': rec.team_ids,

            }

            fieldworkers.append(vals)

        data = {'status': 200, 'response': fieldworkers, 'message': 'All Fieldworkers Fetched'}               return data

아바타
취소

Do you've got a proxy, like nginx?

Do you've got more than one database? and do you filter the database somehow?

작성자

@ Blanco,

1. Yes, I use nginx

2. Yes, I did filter the databases like dbfilter = ^%d$

베스트 답변

You need to pass that session id in the header of each request after authentication. I suggest you to open your log and when you attemp to get or post something your log will tell you what is missing

아바타
취소
작성자

@ Abdullah,

I did passed the session id to each request header on the Android App but always get session expired

관련 게시물 답글 화면 활동
5
5월 25
9629
0
7월 22
5726
0
7월 21
7516
3
8월 19
6337
3
2월 24
14544