Forum Freedom-IP VPN

Forum d'entraide de la communauté Freedom-IP VPN

Vous n'êtes pas identifié(e).

#51 2015-11-28 11:39:11

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API

Pas mieux ..

[INFO] Demande Server
[ OK ] Server
[INFO] Demande userInfo
Traceback (most recent call last):
  File "API_lib.py", line 192, in <module>
    _test()
  File "API_lib.py", line 173, in _test
    api_ret.append(fip.userInfo())
  File "API_lib.py", line 107, in userInfo
    response=json.loads(self._info("userInfo"))
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
 

L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#52 2015-11-28 11:42:09

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

Une petite question tu fais les essais VPN en marche ou non  ?

Edit : en fait cher moi sa fonctionne avec ou sans VPN

Dernière modification par Didier-T (2015-11-28 12:45:32)

Hors ligne

#53 2015-11-28 12:08:40

David
Bof !!!
Inscription : 2012-01-30
Messages : 6 132

Re : Amélioration de l'API

Bonjour ...

Petite question : Où avez-vous trouvé toutes les spécifications de l'API !?

Cordialement, David.

Hors ligne

#54 2015-11-28 12:43:48

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

Bonjour David,
hmz m'a dit comment récupérer les informations.

Edit : nouvel essais, ont finira par l'avoir cette erreur ridicule  devil

en Python3

#! /usr/bin/python3
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import time, platform, json, base64
from urllib.parse import urlencode
from urllib.request import Request
from urllib.request import urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = str(response.readline().decode(encoder)).strip("'<>() ").replace('\'', '\"')
            print(repr(ret))
        else:
            ret = "{}"
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=json.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=json.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=json.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

Dernière modification par Didier-T (2015-11-28 12:59:04)

Hors ligne

#55 2015-11-28 13:17:36

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API

Re Didier .
Jusqu'à présent tous mes retours terminal se sont fait en
passant par le serveur vpn .
Voici le retour pour ton dernier script en python3 :

[INFO] Demande Server
'{"status":"success","fr":{"country":"FR","online":true,"speed_up_bytes":"1952504","speed_down_bytes":"2070660","nbr_logged":"81"},"nl":{"country":"NL","online":true,"speed_up_bytes":"1635642","speed_down_bytes":"1788497","nbr_logged":"62"},"de":{"country":"DE","online":true,"speed_up_bytes":"2989711","speed_down_bytes":"3135564","nbr_logged":"20"},"es":{"country":"ES","online":true,"speed_up_bytes":"1698900","speed_down_bytes":"4235369","nbr_logged":"19"},"uk":{"country":"UK","online":true,"speed_up_bytes":"1053514","speed_down_bytes":"3841444","nbr_logged":"8"},"ie":{"country":"IE","online":true,"speed_up_bytes":"203886","speed_down_bytes":"185435","nbr_logged":"15"},"cz":{"country":"CZ","online":true,"speed_up_bytes":"253670","speed_down_bytes":"1298580","nbr_logged":"14"},"lt":{"country":"LT","online":true,"speed_up_bytes":"879479","speed_down_bytes":"2674479","nbr_logged":"10"},"be":{"country":"BE","online":true,"speed_up_bytes":"2074393","speed_down_bytes":"2290667","nbr_logged":"21"},"pl":{"country":"PL","online":true,"speed_up_bytes":"683475","speed_down_bytes":"672174","nbr_logged":"14"},"ch":{"country":"CH","online":true,"speed_up_bytes":"833339","speed_down_bytes":"2624784","nbr_logged":"15"},"it":{"country":"IT","online":true,"speed_up_bytes":"271977","speed_down_bytes":"2629137","nbr_logged":"7"},"lu":{"country":"LU","online":true,"speed_up_bytes":"9668","speed_down_bytes":"13705","nbr_logged":"9"},"fi":{"country":"FI","online":true,"speed_up_bytes":"125999","speed_down_bytes":"110051","nbr_logged":"9"},"pt":{"country":"PT","online":true,"speed_up_bytes":"290295","speed_down_bytes":"322196","nbr_logged":"4"},"gr":{"country":"GR","online":true,"speed_up_bytes":"5137","speed_down_bytes":"8745","nbr_logged":"7"},"mt":{"country":"MT","online":true,"speed_up_bytes":"441932","speed_down_bytes":"2270348","nbr_logged":"88"},"dk":{"country":"DK","online":true,"speed_up_bytes":"1058388","speed_down_bytes":"1719600","nbr_logged":"12"},"se":{"country":"SE","online":true,"speed_up_bytes":"2179787","speed_down_bytes":"1832957","nbr_logged":"7"},"us":{"country":"US","online":true,"speed_up_bytes":"336329","speed_down_bytes":"349665","nbr_logged":"7"},"ca":{"country":"CA","online":true,"speed_up_bytes":"351761","speed_down_bytes":"325468","nbr_logged":"8"},"ru":{"country":"RU","online":true,"speed_up_bytes":"1060951","speed_down_bytes":"3869435","nbr_logged":"13"},"ua":{"country":"UA","online":true,"speed_up_bytes":"16578","speed_down_bytes":"1932220","nbr_logged":"8"},"ro":{"country":"RO","online":true,"speed_up_bytes":"65434","speed_down_bytes":"1519835","nbr_logged":"12"},"is":{"country":"IS","online":true,"speed_up_bytes":"106050","speed_down_bytes":"98413","nbr_logged":"12"},"lv":{"country":"LV","online":true,"speed_up_bytes":"1182255","speed_down_bytes":"1362984","nbr_logged":"6"},"hr":{"country":"HR","online":true,"speed_up_bytes":"344204","speed_down_bytes":"365730","nbr_logged":"6"},"no":{"country":"NO","online":true,"speed_up_bytes":"1152256","speed_down_bytes":"1135742","nbr_logged":"7"},"si":{"country":"SI","online":true,"speed_up_bytes":"300","speed_down_bytes":"2757","nbr_logged":"4"},"at":{"country":"AT","online":true,"speed_up_bytes":"124516","speed_down_bytes":"151154","nbr_logged":"8"},"bg":{"country":"BG","online":true,"speed_up_bytes":"9344","speed_down_bytes":"1735283","nbr_logged":"3"},"ee":{"country":"EE","online":true,"speed_up_bytes":"332490","speed_down_bytes":"337314","nbr_logged":"6"}}'
[ OK ] Server
[INFO] Demande userInfo
''
Traceback (most recent call last):
  File "API_lib.py", line 192, in <module>
    _test()
  File "API_lib.py", line 173, in _test
    api_ret.append(fip.userInfo())
  File "API_lib.py", line 107, in userInfo
    response=json.loads(self._info("userInfo"))
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
 

Voici le retour terminal sans serveur vpn , le résultat est identique .

[INFO] Demande Server
'{"status":"success","fr":{"country":"FR","online":true,"speed_up_bytes":"1809383","speed_down_bytes":"2084320","nbr_logged":"81"},"nl":{"country":"NL","online":true,"speed_up_bytes":"1545821","speed_down_bytes":"3791285","nbr_logged":"61"},"de":{"country":"DE","online":true,"speed_up_bytes":"2377994","speed_down_bytes":"2760738","nbr_logged":"21"},"es":{"country":"ES","online":true,"speed_up_bytes":"1310662","speed_down_bytes":"1627011","nbr_logged":"18"},"uk":{"country":"UK","online":true,"speed_up_bytes":"192610","speed_down_bytes":"214936","nbr_logged":"8"},"ie":{"country":"IE","online":true,"speed_up_bytes":"460617","speed_down_bytes":"1978447","nbr_logged":"15"},"cz":{"country":"CZ","online":true,"speed_up_bytes":"180137","speed_down_bytes":"196529","nbr_logged":"14"},"lt":{"country":"LT","online":true,"speed_up_bytes":"1290843","speed_down_bytes":"1230055","nbr_logged":"10"},"be":{"country":"BE","online":true,"speed_up_bytes":"1890265","speed_down_bytes":"3976284","nbr_logged":"20"},"pl":{"country":"PL","online":true,"speed_up_bytes":"571799","speed_down_bytes":"517785","nbr_logged":"14"},"ch":{"country":"CH","online":true,"speed_up_bytes":"622634","speed_down_bytes":"611676","nbr_logged":"16"},"it":{"country":"IT","online":true,"speed_up_bytes":"281012","speed_down_bytes":"271122","nbr_logged":"7"},"lu":{"country":"LU","online":true,"speed_up_bytes":"64944","speed_down_bytes":"2083090","nbr_logged":"9"},"fi":{"country":"FI","online":true,"speed_up_bytes":"68293","speed_down_bytes":"93522","nbr_logged":"9"},"pt":{"country":"PT","online":true,"speed_up_bytes":"224522","speed_down_bytes":"281602","nbr_logged":"4"},"gr":{"country":"GR","online":true,"speed_up_bytes":"52439","speed_down_bytes":"2341692","nbr_logged":"7"},"mt":{"country":"MT","online":true,"speed_up_bytes":"429978","speed_down_bytes":"532529","nbr_logged":"90"},"dk":{"country":"DK","online":true,"speed_up_bytes":"819890","speed_down_bytes":"1011956","nbr_logged":"12"},"se":{"country":"SE","online":true,"speed_up_bytes":"2337358","speed_down_bytes":"4134677","nbr_logged":"7"},"us":{"country":"US","online":true,"speed_up_bytes":"348110","speed_down_bytes":"518505","nbr_logged":"7"},"ca":{"country":"CA","online":true,"speed_up_bytes":"499967","speed_down_bytes":"561429","nbr_logged":"8"},"ru":{"country":"RU","online":true,"speed_up_bytes":"2091423","speed_down_bytes":"2034857","nbr_logged":"13"},"ua":{"country":"UA","online":true,"speed_up_bytes":"7435","speed_down_bytes":"7086","nbr_logged":"5"},"ro":{"country":"RO","online":true,"speed_up_bytes":"274333","speed_down_bytes":"270487","nbr_logged":"11"},"is":{"country":"IS","online":true,"speed_up_bytes":"109349","speed_down_bytes":"130612","nbr_logged":"12"},"lv":{"country":"LV","online":true,"speed_up_bytes":"1084117","speed_down_bytes":"1299663","nbr_logged":"5"},"hr":{"country":"HR","online":true,"speed_up_bytes":"362427","speed_down_bytes":"934118","nbr_logged":"6"},"no":{"country":"NO","online":true,"speed_up_bytes":"1191932","speed_down_bytes":"1240369","nbr_logged":"8"},"si":{"country":"SI","online":true,"speed_up_bytes":"12706","speed_down_bytes":"2188512","nbr_logged":"4"},"at":{"country":"AT","online":true,"speed_up_bytes":"122189","speed_down_bytes":"130157","nbr_logged":"7"},"bg":{"country":"BG","online":true,"speed_up_bytes":"203","speed_down_bytes":"2948","nbr_logged":"2"},"ee":{"country":"EE","online":true,"speed_up_bytes":"284995","speed_down_bytes":"2027796","nbr_logged":"6"}}'
[ OK ] Server
[INFO] Demande userInfo
''
Traceback (most recent call last):
  File "API_lib.py", line 192, in <module>
    _test()
  File "API_lib.py", line 173, in _test
    api_ret.append(fip.userInfo())
  File "API_lib.py", line 107, in userInfo
    response=json.loads(self._info("userInfo"))
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0) 

Dernière modification par Patrick1969 (2015-11-28 13:22:43)


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#56 2015-11-28 13:22:32

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

Patrick essaye sa, je crois avoir vue le soucis

#! /usr/bin/python3
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import time, platform, json, base64
from urllib.parse import urlencode
from urllib.request import Request
from urllib.request import urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = str(response.readline().decode(encoder)).strip("'<>() ").replace('\'', '\"')
            print(repr(ret))
        else:
            ret = "{}"
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=json.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=json.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=json.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server']#,'userInfo','livestats']
    api_ret.append(fip.Server())
#    api_ret.append(fip.userInfo())
#    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

Hors ligne

#57 2015-11-28 13:27:40

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API

big_smile , je crois que tu y es Didier .
Retour terminal sans connexion au serveur vpn .
Je fait vite un petit essai avec .

[INFO] Demande Server
'{"status":"success","fr":{"country":"FR","online":true,"speed_up_bytes":"1877815","speed_down_bytes":"2703828","nbr_logged":"82"},"nl":{"country":"NL","online":true,"speed_up_bytes":"1649985","speed_down_bytes":"1773674","nbr_logged":"61"},"de":{"country":"DE","online":true,"speed_up_bytes":"3566326","speed_down_bytes":"3624282","nbr_logged":"21"},"es":{"country":"ES","online":true,"speed_up_bytes":"1408921","speed_down_bytes":"3419919","nbr_logged":"18"},"uk":{"country":"UK","online":true,"speed_up_bytes":"287191","speed_down_bytes":"1352106","nbr_logged":"8"},"ie":{"country":"IE","online":true,"speed_up_bytes":"239796","speed_down_bytes":"245365","nbr_logged":"15"},"cz":{"country":"CZ","online":true,"speed_up_bytes":"219673","speed_down_bytes":"1027776","nbr_logged":"14"},"lt":{"country":"LT","online":true,"speed_up_bytes":"1148040","speed_down_bytes":"3134518","nbr_logged":"10"},"be":{"country":"BE","online":true,"speed_up_bytes":"1928528","speed_down_bytes":"2114568","nbr_logged":"21"},"pl":{"country":"PL","online":true,"speed_up_bytes":"491904","speed_down_bytes":"482034","nbr_logged":"14"},"ch":{"country":"CH","online":true,"speed_up_bytes":"576602","speed_down_bytes":"1430184","nbr_logged":"16"},"it":{"country":"IT","online":true,"speed_up_bytes":"245319","speed_down_bytes":"2695643","nbr_logged":"7"},"lu":{"country":"LU","online":true,"speed_up_bytes":"101009","speed_down_bytes":"87027","nbr_logged":"9"},"fi":{"country":"FI","online":true,"speed_up_bytes":"55418","speed_down_bytes":"76660","nbr_logged":"9"},"pt":{"country":"PT","online":true,"speed_up_bytes":"300289","speed_down_bytes":"301739","nbr_logged":"4"},"gr":{"country":"GR","online":true,"speed_up_bytes":"76808","speed_down_bytes":"77879","nbr_logged":"7"},"mt":{"country":"MT","online":true,"speed_up_bytes":"419571","speed_down_bytes":"1592329","nbr_logged":"88"},"dk":{"country":"DK","online":true,"speed_up_bytes":"892254","speed_down_bytes":"2113665","nbr_logged":"12"},"se":{"country":"SE","online":true,"speed_up_bytes":"517842","speed_down_bytes":"440648","nbr_logged":"7"},"us":{"country":"US","online":true,"speed_up_bytes":"342302","speed_down_bytes":"517062","nbr_logged":"7"},"ca":{"country":"CA","online":true,"speed_up_bytes":"417928","speed_down_bytes":"509984","nbr_logged":"8"},"ru":{"country":"RU","online":true,"speed_up_bytes":"1362076","speed_down_bytes":"2038904","nbr_logged":"13"},"ua":{"country":"UA","online":true,"speed_up_bytes":"12192","speed_down_bytes":"927197","nbr_logged":"5"},"ro":{"country":"RO","online":true,"speed_up_bytes":"86920","speed_down_bytes":"2862224","nbr_logged":"11"},"is":{"country":"IS","online":true,"speed_up_bytes":"90406","speed_down_bytes":"117772","nbr_logged":"12"},"lv":{"country":"LV","online":true,"speed_up_bytes":"1249470","speed_down_bytes":"1239605","nbr_logged":"6"},"hr":{"country":"HR","online":true,"speed_up_bytes":"329120","speed_down_bytes":"328178","nbr_logged":"6"},"no":{"country":"NO","online":true,"speed_up_bytes":"1110944","speed_down_bytes":"1981294","nbr_logged":"7"},"si":{"country":"SI","online":true,"speed_up_bytes":"976","speed_down_bytes":"1427","nbr_logged":"4"},"at":{"country":"AT","online":true,"speed_up_bytes":"139025","speed_down_bytes":"149298","nbr_logged":"7"},"bg":{"country":"BG","online":true,"speed_up_bytes":"6450","speed_down_bytes":"1425580","nbr_logged":"2"},"ee":{"country":"EE","online":true,"speed_up_bytes":"287878","speed_down_bytes":"330679","nbr_logged":"6"}}'
[ OK ] Server
Arbre retour fonction Server() :
[pl][speed_up_bytes]=491904
[pl][speed_down_bytes]=482034
[pl][country]=PL
[pl][nbr_logged]=14
[pl][online]=True
[lt][speed_up_bytes]=1148040
[lt][speed_down_bytes]=3134518
[lt][country]=LT
[lt][nbr_logged]=10
[lt][online]=True
[uk][speed_up_bytes]=287191
[uk][speed_down_bytes]=1352106
[uk][country]=UK
[uk][nbr_logged]=8
[uk][online]=True
[ch][speed_up_bytes]=576602
[ch][speed_down_bytes]=1430184
[ch][country]=CH
[ch][nbr_logged]=16
[ch][online]=True
[ee][speed_up_bytes]=287878
[ee][speed_down_bytes]=330679
[ee][country]=EE
[ee][nbr_logged]=6
[ee][online]=True
[is][speed_up_bytes]=90406
[is][speed_down_bytes]=117772
[is][country]=IS
[is][nbr_logged]=12
[is][online]=True
[ua][speed_up_bytes]=12192
[ua][speed_down_bytes]=927197
[ua][country]=UA
[ua][nbr_logged]=5
[ua][online]=True
[fi][speed_up_bytes]=55418
[fi][speed_down_bytes]=76660
[fi][country]=FI
[fi][nbr_logged]=9
[fi][online]=True
[ie][speed_up_bytes]=239796
[ie][speed_down_bytes]=245365
[ie][country]=IE
[ie][nbr_logged]=15
[ie][online]=True
[us][speed_up_bytes]=342302
[us][speed_down_bytes]=517062
[us][country]=US
[us][nbr_logged]=7
[us][online]=True
[mt][speed_up_bytes]=419571
[mt][speed_down_bytes]=1592329
[mt][country]=MT
[mt][nbr_logged]=88
[mt][online]=True
[nl][speed_up_bytes]=1649985
[nl][speed_down_bytes]=1773674
[nl][country]=NL
[nl][nbr_logged]=61
[nl][online]=True
[es][speed_up_bytes]=1408921
[es][speed_down_bytes]=3419919
[es][country]=ES
[es][nbr_logged]=18
[es][online]=True
[bg][speed_up_bytes]=6450
[bg][speed_down_bytes]=1425580
[bg][country]=BG
[bg][nbr_logged]=2
[bg][online]=True
[no][speed_up_bytes]=1110944
[no][speed_down_bytes]=1981294
[no][country]=NO
[no][nbr_logged]=7
[no][online]=True
[be][speed_up_bytes]=1928528
[be][speed_down_bytes]=2114568
[be][country]=BE
[be][nbr_logged]=21
[be][online]=True
[at][speed_up_bytes]=139025
[at][speed_down_bytes]=149298
[at][country]=AT
[at][nbr_logged]=7
[at][online]=True
[fr][speed_up_bytes]=1877815
[fr][speed_down_bytes]=2703828
[fr][country]=FR
[fr][nbr_logged]=82
[fr][online]=True
[si][speed_up_bytes]=976
[si][speed_down_bytes]=1427
[si][country]=SI
[si][nbr_logged]=4
[si][online]=True
[it][speed_up_bytes]=245319
[it][speed_down_bytes]=2695643
[it][country]=IT
[it][nbr_logged]=7
[it][online]=True
[ca][speed_up_bytes]=417928
[ca][speed_down_bytes]=509984
[ca][country]=CA
[ca][nbr_logged]=8
[ca][online]=True
[status]=success
[de][speed_up_bytes]=3566326
[de][speed_down_bytes]=3624282
[de][country]=DE
[de][nbr_logged]=21
[de][online]=True
[cz][speed_up_bytes]=219673
[cz][speed_down_bytes]=1027776
[cz][country]=CZ
[cz][nbr_logged]=14
[cz][online]=True
[lv][speed_up_bytes]=1249470
[lv][speed_down_bytes]=1239605
[lv][country]=LV
[lv][nbr_logged]=6
[lv][online]=True
[ru][speed_up_bytes]=1362076
[ru][speed_down_bytes]=2038904
[ru][country]=RU
[ru][nbr_logged]=13
[ru][online]=True
[dk][speed_up_bytes]=892254
[dk][speed_down_bytes]=2113665
[dk][country]=DK
[dk][nbr_logged]=12
[dk][online]=True
[ro][speed_up_bytes]=86920
[ro][speed_down_bytes]=2862224
[ro][country]=RO
[ro][nbr_logged]=11
[ro][online]=True
[se][speed_up_bytes]=517842
[se][speed_down_bytes]=440648
[se][country]=SE
[se][nbr_logged]=7
[se][online]=True
[gr][speed_up_bytes]=76808
[gr][speed_down_bytes]=77879
[gr][country]=GR
[gr][nbr_logged]=7
[gr][online]=True
[pt][speed_up_bytes]=300289
[pt][speed_down_bytes]=301739
[pt][country]=PT
[pt][nbr_logged]=4
[pt][online]=True
[hr][speed_up_bytes]=329120
[hr][speed_down_bytes]=328178
[hr][country]=HR
[hr][nbr_logged]=6
[hr][online]=True
[lu][speed_up_bytes]=101009
[lu][speed_down_bytes]=87027
[lu][country]=LU
[lu][nbr_logged]=9
[lu][online]=True


Chronomètre :
Temp consultation API : 0.2295544147491455
Temp exploration arbres : 0.0019030570983886719
Temp consultation API + exploration arbres : 0.23145747184753418
 

Petit coup de "flip" dans un premier temps , j'avais oublié de redémarrer le pare-feu  ops
Voilà le résultat avec le serveur vpn en fonction :

[INFO] Demande Server
'{"status":"success","fr":{"country":"FR","online":true,"speed_up_bytes":"2602189","speed_down_bytes":"3131057","nbr_logged":"82"},"nl":{"country":"NL","online":true,"speed_up_bytes":"1606911","speed_down_bytes":"3550104","nbr_logged":"64"},"de":{"country":"DE","online":true,"speed_up_bytes":"3114108","speed_down_bytes":"4057932","nbr_logged":"21"},"es":{"country":"ES","online":true,"speed_up_bytes":"1325898","speed_down_bytes":"1431505","nbr_logged":"18"},"uk":{"country":"UK","online":true,"speed_up_bytes":"461961","speed_down_bytes":"489983","nbr_logged":"8"},"ie":{"country":"IE","online":true,"speed_up_bytes":"121071","speed_down_bytes":"1434202","nbr_logged":"13"},"cz":{"country":"CZ","online":true,"speed_up_bytes":"216626","speed_down_bytes":"213154","nbr_logged":"14"},"lt":{"country":"LT","online":true,"speed_up_bytes":"1334508","speed_down_bytes":"1293619","nbr_logged":"10"},"be":{"country":"BE","online":true,"speed_up_bytes":"2807896","speed_down_bytes":"4358949","nbr_logged":"21"},"pl":{"country":"PL","online":true,"speed_up_bytes":"445887","speed_down_bytes":"2155615","nbr_logged":"14"},"ch":{"country":"CH","online":true,"speed_up_bytes":"862351","speed_down_bytes":"872747","nbr_logged":"16"},"it":{"country":"IT","online":true,"speed_up_bytes":"302505","speed_down_bytes":"291742","nbr_logged":"7"},"lu":{"country":"LU","online":true,"speed_up_bytes":"59378","speed_down_bytes":"656956","nbr_logged":"10"},"fi":{"country":"FI","online":true,"speed_up_bytes":"68340","speed_down_bytes":"89471","nbr_logged":"9"},"pt":{"country":"PT","online":true,"speed_up_bytes":"226371","speed_down_bytes":"227644","nbr_logged":"3"},"gr":{"country":"GR","online":true,"speed_up_bytes":"6537","speed_down_bytes":"9999","nbr_logged":"7"},"mt":{"country":"MT","online":true,"speed_up_bytes":"560050","speed_down_bytes":"599811","nbr_logged":"88"},"dk":{"country":"DK","online":true,"speed_up_bytes":"570033","speed_down_bytes":"655276","nbr_logged":"13"},"se":{"country":"SE","online":true,"speed_up_bytes":"743865","speed_down_bytes":"743192","nbr_logged":"7"},"us":{"country":"US","online":true,"speed_up_bytes":"270063","speed_down_bytes":"723374","nbr_logged":"7"},"ca":{"country":"CA","online":true,"speed_up_bytes":"519220","speed_down_bytes":"555794","nbr_logged":"8"},"ru":{"country":"RU","online":true,"speed_up_bytes":"962427","speed_down_bytes":"972766","nbr_logged":"13"},"ua":{"country":"UA","online":true,"speed_up_bytes":"100825","speed_down_bytes":"98772","nbr_logged":"6"},"ro":{"country":"RO","online":true,"speed_up_bytes":"57824","speed_down_bytes":"60114","nbr_logged":"11"},"is":{"country":"IS","online":true,"speed_up_bytes":"125977","speed_down_bytes":"3411737","nbr_logged":"12"},"lv":{"country":"LV","online":true,"speed_up_bytes":"1172962","speed_down_bytes":"3173173","nbr_logged":"5"},"hr":{"country":"HR","online":true,"speed_up_bytes":"431055","speed_down_bytes":"2229898","nbr_logged":"6"},"no":{"country":"NO","online":true,"speed_up_bytes":"1127150","speed_down_bytes":"1239281","nbr_logged":"7"},"si":{"country":"SI","online":true,"speed_up_bytes":"9381","speed_down_bytes":"1321887","nbr_logged":"4"},"at":{"country":"AT","online":true,"speed_up_bytes":"48403","speed_down_bytes":"1803845","nbr_logged":"7"},"bg":{"country":"BG","online":true,"speed_up_bytes":"198","speed_down_bytes":"2749","nbr_logged":"2"},"ee":{"country":"EE","online":true,"speed_up_bytes":"250437","speed_down_bytes":"1353231","nbr_logged":"6"}}'
[ OK ] Server
Arbre retour fonction Server() :
[hr][country]=HR
[hr][nbr_logged]=6
[hr][online]=True
[hr][speed_up_bytes]=431055
[hr][speed_down_bytes]=2229898
[ua][country]=UA
[ua][nbr_logged]=6
[ua][online]=True
[ua][speed_up_bytes]=100825
[ua][speed_down_bytes]=98772
[nl][country]=NL
[nl][nbr_logged]=64
[nl][online]=True
[nl][speed_up_bytes]=1606911
[nl][speed_down_bytes]=3550104
[de][country]=DE
[de][nbr_logged]=21
[de][online]=True
[de][speed_up_bytes]=3114108
[de][speed_down_bytes]=4057932
[ca][country]=CA
[ca][nbr_logged]=8
[ca][online]=True
[ca][speed_up_bytes]=519220
[ca][speed_down_bytes]=555794
[at][country]=AT
[at][nbr_logged]=7
[at][online]=True
[at][speed_up_bytes]=48403
[at][speed_down_bytes]=1803845
[no][country]=NO
[no][nbr_logged]=7
[no][online]=True
[no][speed_up_bytes]=1127150
[no][speed_down_bytes]=1239281
[gr][country]=GR
[gr][nbr_logged]=7
[gr][online]=True
[gr][speed_up_bytes]=6537
[gr][speed_down_bytes]=9999
[ee][country]=EE
[ee][nbr_logged]=6
[ee][online]=True
[ee][speed_up_bytes]=250437
[ee][speed_down_bytes]=1353231
[mt][country]=MT
[mt][nbr_logged]=88
[mt][online]=True
[mt][speed_up_bytes]=560050
[mt][speed_down_bytes]=599811
[bg][country]=BG
[bg][nbr_logged]=2
[bg][online]=True
[bg][speed_up_bytes]=198
[bg][speed_down_bytes]=2749
[ie][country]=IE
[ie][nbr_logged]=13
[ie][online]=True
[ie][speed_up_bytes]=121071
[ie][speed_down_bytes]=1434202
[pt][country]=PT
[pt][nbr_logged]=3
[pt][online]=True
[pt][speed_up_bytes]=226371
[pt][speed_down_bytes]=227644
[lv][country]=LV
[lv][nbr_logged]=5
[lv][online]=True
[lv][speed_up_bytes]=1172962
[lv][speed_down_bytes]=3173173
[es][country]=ES
[es][nbr_logged]=18
[es][online]=True
[es][speed_up_bytes]=1325898
[es][speed_down_bytes]=1431505
[ch][country]=CH
[ch][nbr_logged]=16
[ch][online]=True
[ch][speed_up_bytes]=862351
[ch][speed_down_bytes]=872747
[it][country]=IT
[it][nbr_logged]=7
[it][online]=True
[it][speed_up_bytes]=302505
[it][speed_down_bytes]=291742
[pl][country]=PL
[pl][nbr_logged]=14
[pl][online]=True
[pl][speed_up_bytes]=445887
[pl][speed_down_bytes]=2155615
[is][country]=IS
[is][nbr_logged]=12
[is][online]=True
[is][speed_up_bytes]=125977
[is][speed_down_bytes]=3411737
[fr][country]=FR
[fr][nbr_logged]=82
[fr][online]=True
[fr][speed_up_bytes]=2602189
[fr][speed_down_bytes]=3131057
[us][country]=US
[us][nbr_logged]=7
[us][online]=True
[us][speed_up_bytes]=270063
[us][speed_down_bytes]=723374
[ro][country]=RO
[ro][nbr_logged]=11
[ro][online]=True
[ro][speed_up_bytes]=57824
[ro][speed_down_bytes]=60114
[si][country]=SI
[si][nbr_logged]=4
[si][online]=True
[si][speed_up_bytes]=9381
[si][speed_down_bytes]=1321887
[ru][country]=RU
[ru][nbr_logged]=13
[ru][online]=True
[ru][speed_up_bytes]=962427
[ru][speed_down_bytes]=972766
[uk][country]=UK
[uk][nbr_logged]=8
[uk][online]=True
[uk][speed_up_bytes]=461961
[uk][speed_down_bytes]=489983
[status]=success
[cz][country]=CZ
[cz][nbr_logged]=14
[cz][online]=True
[cz][speed_up_bytes]=216626
[cz][speed_down_bytes]=213154
[lt][country]=LT
[lt][nbr_logged]=10
[lt][online]=True
[lt][speed_up_bytes]=1334508
[lt][speed_down_bytes]=1293619
[be][country]=BE
[be][nbr_logged]=21
[be][online]=True
[be][speed_up_bytes]=2807896
[be][speed_down_bytes]=4358949
[se][country]=SE
[se][nbr_logged]=7
[se][online]=True
[se][speed_up_bytes]=743865
[se][speed_down_bytes]=743192
[lu][country]=LU
[lu][nbr_logged]=10
[lu][online]=True
[lu][speed_up_bytes]=59378
[lu][speed_down_bytes]=656956
[fi][country]=FI
[fi][nbr_logged]=9
[fi][online]=True
[fi][speed_up_bytes]=68340
[fi][speed_down_bytes]=89471
[dk][country]=DK
[dk][nbr_logged]=13
[dk][online]=True
[dk][speed_up_bytes]=570033
[dk][speed_down_bytes]=655276


Chronomètre :
Temp consultation API : 0.5270955562591553
Temp exploration arbres : 0.0020694732666015625
Temp consultation API + exploration arbres : 0.5291650295257568

lol , tu es venu , tu as vu et tu as vaincu .
Je ferait un essai ce soir sous windows avec python3
Merci de ta patience , à+ .

Dernière modification par Patrick1969 (2015-11-28 13:43:25)


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#58 2015-11-28 13:35:59

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

l'API ne retourne pas d'information pour userInfo car il n'y a rien a dire neutral , depuis le début je l'avais sous les yeux ops cry (vas falloir que je m’achète des lunettes glasses )
Ce code devrait fonctionner, en tout cas sous linux, je ne sais pas ce que le passage a python 3 vas avoir changé sous Windows roll

#! /usr/bin/python3
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import time, platform, json, base64
from urllib.parse import urlencode
from urllib.request import Request
from urllib.request import urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        try:
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = str(response.readline().decode(encoder)).strip("'<>() ").replace('\'', '\"')
        except:
            ret = '{"status":"retour nul"}'
            pass
        print(repr(ret))
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=json.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=json.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=json.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

Edit : en fait metalux et toi n'avez certainement pas d'abonnement, d’où le manque d'information sur userinfo, si ce n'est pas le cas c'est un soucis de l'API d'hmz
et oui Veni Vidi Vici

A+,
Didier.

Dernière modification par Didier-T (2015-11-28 14:03:45)

Hors ligne

#59 2015-11-28 13:52:19

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#60 2015-11-28 13:53:39

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

je vais devenir dingue, donc il y a un autre soucis  cry

Hors ligne

#61 2015-11-28 14:32:31

ptit_poulet
Community Manager & Chef du support technique
Inscription : 2012-08-31
Messages : 3 102

Re : Amélioration de l'API


J'aime bien troller David toute la journée pour l’empêcher de s'ennuyer devil

Hors ligne

#62 2015-11-28 14:35:20

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

lol... Méchant  tongue

Hors ligne

#63 2015-11-28 15:17:37

David
Bof !!!
Inscription : 2012-01-30
Messages : 6 132

Re : Amélioration de l'API

Hors ligne

#64 2015-11-28 15:47:38

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

Hors ligne

#65 2015-11-28 16:47:54

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API

Voilà ce que j'obtiens sous windows 8.1 pro .

  File "C:\Users\patrick\Desktop\API_lib.py", line 56
SyntaxError: Non-UTF-8 code starting with '\xe9' in file C:\Users\patrick\Desktop\API_lib.py on line 56, but no encoding declared; see http:
//python.org/dev/peps/pep-0263/ for details
 

 

Une petite idée à me soumettre éventuellement ?
Merci , cordialement , Patrick1969 .


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#66 2015-11-28 16:53:48

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

il n'a pas aimé l'accent sur "vérifier".
tu as bien utilisé python 3 ?
en même temps tu peut utiliser l'exe que j'ai mis plus haut

Hors ligne

#67 2015-11-28 19:58:46

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API

Oui Didier , j'utilise bien python3 avec la version 3.5.150.0
Voici le résultat en utilisant ton exécutable :

Cette version de C:\Users\patrick\Desktop\API_lib.exe n’est pas compatible avec la version de Windows actuellement exécutée. Vérifiez dans l
es informations système de votre ordinateur, puis contactez l’éditeur de logiciel.
 
C:\Windows\System32>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 

A+

Dernière modification par Patrick1969 (2015-11-29 10:58:59)


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#68 2015-11-29 15:58:35

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

Bonjour,
bon, je crois que je vais laisser les pro de Windows nous faire l’exécutable (il y aura bien une âme charitable  kiss )

je n'ai pas rencontré le soucis avec les accents que tu as remonté plus haut Patrick, je ne peut donc pas tester cette solution

#! /usr/bin/python3
# -*- coding: utf-8 -*-
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

from time import time
from platform import system
from json import loads
from base64 import encodestring
from urllib.parse import urlencode
from urllib.request import Request, urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password, verbeux):
        self.v=verbeux
        self.user=user
        self.password=encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                self.v and print("FAIL %s" % e)
                if e.code==401:
                    self.v and print(u"INFO Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                self.v and print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    self.v and print(u"[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        try:
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = str(response.readline().decode(encoder)).strip("'<>() ").replace('\'', '\"')
        except:
            ret = '{"status":"retour nul"}'
            pass
#        print(repr(ret))
        return ret

    def _info(self, recherche):
        if system() != 'Linux':
            self.v and print("INFO Demande "+recherche)
        else:
            self.v and print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            if system() != 'Linux':
                self.v and print("OK "+recherche)
            else:
                self.v and print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            if system() != 'Linux':
                self.v and print("FAIL Erreur "+status)
            else:
                self.v and print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])
    timer.start()
    api_ret=[]
    fip=api(user, password, True)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        if system() != 'Linux':
            print("Arbre retour fonction :".format(list_api[x]))
        else:
            print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    if system() != 'Linux':
        print("Chronomètre :")
    else:
        print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

A+,
Didier.

Hors ligne

#69 2015-11-29 18:07:11

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API

Bonsoir à tous , bonsoir Didier-T .
En ce qui me concerne l'exécutable windows n'est pas une obligation pour moi .
Je l'ai testé juste pour que tu es un retour sur ton travail . Depuis que j'ai "découvert"
l'univers linux , je m'investis vraiment dans ce système d'exploitation . A terme , je compte
bien passer tous mes pc sur linux mais , tant que je ne maitrise pas à " fond ", windows
reste ma solution pour les choses courantes .
Reste à trouver pourquoi aucune "userinfo " n'est donnée malgré un abonnement .
Un grand merci pour ton partage de script et pour le temps que tu passes à travailler dessus .
Je te souhaite une bonne fin de week-end , cordialement , Patrick1969 .

Dernière modification par Patrick1969 (2015-11-29 18:07:34)


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#70 2015-12-05 13:31:59

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#71 2015-12-05 14:05:57

Didier-T
Contributeurs Confirmés
Lieu : Argenteuil
Inscription : 2014-02-01
Messages : 323

Re : Amélioration de l'API

Bonjour Patrick,
En fait pour le moment il n'y a que hmz qui puisse voir ce qu'il ce passe

Hors ligne

#72 2015-12-06 11:09:48

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API

Dernière modification par Patrick1969 (2015-12-06 11:12:20)


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#73 2015-12-14 20:02:44

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API

Bonsoir à tous , bonsoir hmz .
Juste à titre d'information , j'aurai voulu savoir si vous avez déjà pu avancer
un peu sur le petit souci concernant l'api .
Cordialement , Patrick1969.


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

#74 2015-12-14 21:02:37

hmz
Administrateur
Inscription : 2013-03-21
Messages : 2 139

Re : Amélioration de l'API

Hello,

J'attends toujours le mauvais retour API par MP.

Cheers


If privacy is outlawed, only outlaws will have privacy.

Hors ligne

#75 2015-12-15 08:41:17

Patrick1969
Membre
Inscription : 2015-01-23
Messages : 283

Re : Amélioration de l'API

Bonjour à tous .
Terriblement efficace notre Merlin de la programmation .
Notre magicien a encore frappé .... Si , si l'api est fonctionnelle ,
tu peux dormir en paix Didier   wink
Un grand merci à Didier pour ses scripts , un immense merci à hmz pour la mise
en place de l'api et de son implication pour le suivi .
Passez un agréable journée , qu'elle soit remplie d' Happy . big_smile
Cordialement , Patrick1969 .


L'accès à ce forum reste un privilège et non un droit , n'oubliez pas que nous sommes une communauté et non pas un dû .

Hors ligne

Pied de page des forums