adzhurinskij/phpipam-client

Request is not valid

Opened this issue · 2 comments

Hi,

I wrote a very basic code but it always game code 400, request is not valid:

from phpipam_client import PhpIpamClient, GET

ipam = PhpIpamClient(
        url='https://myurl.local',
        app_id='myapp',
        token='ipam_provided_appcode',
        encryption=True,
)

response=ipam.get('/devices/')
print (response)

I tried the same with a basic rest script and it works fine:

import requests
import json

app='myapp'
appCode='ipam_provided_appcode'
controller=input('Type the controller to perform the search: [subnets|addresses]\n ')
action='search'
    
if controller == ('subnets' or 'addresses'):
        target=input('Type the IP address/subnet to search\n ')
        url=f'https://myurl/api/{app}/{controller}/{action}/{target}/'
        response = requests.get(url, headers={
            "token": appCode,
        })

        response = (response.json())
        print (json.dumps(response, indent=4))
   
else:
        print ('Error: invalid target\n')

What am I doing wrong?

phpipam_client 0.4.0
python 3.6.8

Good. Then it isn't just me. Seeing the same.
Python 3.7.7
phpipam-client 0.4.0

Tried playing with the url as well, but no go,

I'm also here, sharing my founds:

python 3.8
phpipam from master branch
phpipam-client 0.4.0

using the @gpipito code example as test

  • If phpipam UI -> Administration -> API -> App security = Encrypted

in phpipam, config.php with $api_crypt_encryption_library = "mcrypt";
and it works.

  • If phpipam UI -> Administration -> API -> App security = SSL with App code token (which seems recommended: phpipam/phpipam#2316)

no changes needed in config.php (default to openssl)
and in phpipam-client, just by commenting the section below in client.py (quick way to test):

    #if not self._api_encryption:
    #    self.login()

changing the parameter encryption to False in the code, and it works also.

hope it could help