adzhurinskij / phpipam-client

PHPIPAM Python RESP API Client
MIT License
6 stars 0 forks source link

Request is not valid #7

Open gpipito opened 4 years ago

gpipito commented 4 years ago

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

dagbdagb commented 4 years ago

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,

hyperpouet commented 4 years ago

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

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

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