api/permission delete gives NullPointerException error

Mayur2 years ago

here i want to delete permission between device and geofeceid

here is my code

here cookie is list which contain jssessionid and my traccar domain id

headers = {'Cookie': cookie[0], 'Content-Type': 'application/json', 'Accept': 'application/json'}

for geofence in geofence_ids:
                params = {'deviceId':int(self.ref),'geofenceId':geofence}
                r = requests.delete(url=cookie[1] + 'api/permissions', headers=headers, params=params)
Anton Tananaev2 years ago

It's impossible to tell what you have in each variable. Please provide actual formatted request example.

Mayur2 years ago

this is my code check

url = "xyz.demo.com"
traccar_username = "username"
traccar_password = "password"

def login():
    response = requests.post(url + '/api/session', data={'email': traccar_username, 'password': traccar_password})
    return response.headers.get('Set-Cookie') # here we return jssessionID using session api

def add_geofences():
    cookie = login()
    headers = {'Cookie': cookie, 'Content-Type': 'application/json'} # Here we add session id to header
    params = {'deviceId':3,'geofenceId':15} # here we will create parameter to add device and geofence ID (integer)
    r = requests.delete(url=url+ '/api/permissions', headers=headers, params=params)
    # and at that point i got this NullPointerException error

SAME ISSUE FOR ADD PERMISSION I GOT

Anton Tananaev2 years ago

You need to get full stack trace for the exception.

Mayur2 years ago

here i got this thing in response

{'_content': b'NullPointerException (PermissionsResource:65 < *:76 < *:93 < ...)', '_content_consumed': True, '_next': None, 'status_code': 400, 'headers': {'Date': 'Mon, 13 Jun 2022 09:27:48 GMT', 'Content-Type': 'application/json', 'access-control-allow-headers': 'origin, content-type, accept, authorization', 'access-control-allow-credentials': 'true', 'access-control-allow-methods': 'GET, POST, PUT, DELETE, OPTIONS', 'access-control-allow-origin': '*', 'Content-Length': '65', 'Server': 'Jetty(10.0.7)'}, 'raw': <urllib3.response.HTTPResponse object at 0x7fd5cee018b0>, 'url': 'http://xyz.demo.com/api/permissions?deviceId=3&geofenceId=15', 'encoding': 'utf-8', 'history': [], 'reason': 'Bad Request', 'cookies': <RequestsCookieJar[]>, 'elapsed': datetime.timedelta(microseconds=301821), 'request': <PreparedRequest [POST]>, 'connection': <requests.adapters.HTTPAdapter object at 0x7fd5d0156100>}
Anton Tananaev2 years ago

What version are you using?

Mayur2 years ago

version 5.0 i am using

Anton Tananaev2 years ago

It looks like there's some issue with the request, so I think we're back to my original comment:

Please provide actual formatted request example.

Mayur2 years ago

This is the real code just URL and credentials are different.

Also i checked in postman and same it gives error 400 bad request

Mayur2 years ago

Here I am working in python

Anton Tananaev2 years ago

There's no need to write in bold. It's not helping with anything.

If you're unable to provide the request, I don't think I would be able to help you any further.