Code Monkey home page Code Monkey logo

python-wialon's Introduction

Wialon

Wialon is a Python wrapper for Remote Api. (Now with support for Python 3 since v1.0.2)

For async implementation please check o-murphy:py-aiowialon

Installation

pip install python-wialon

Usage

from wialon import Wialon, WialonError

try:
    wialon_api = Wialon()
    # old username and password login is deprecated, use token login
    result = wialon_api.token_login(token='YOUR WIALON USER TOKEN')
    wialon_api.sid = result['eid']

    result = wialon_api.avl_evts()

    wialon_api.core_logout()
except WialonError as e:
    pass

API Documentation

Wialon Remote Api documentation

python-wialon's People

Contributors

achernetsky avatar ashmigelski avatar csotelo avatar darthnall avatar lenka42 avatar wialon avatar zzzant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-wialon's Issues

Cannot call the API using complex params

I'm trying the following:

from wialon import Wialon
from wialon import WialonError

try:
    wialon_api = Wialon()
    result = wialon_api.token_login(token=token)
    wialon_api.sid = result['eid']

    params = '{"spec":{"itemsType":"avl_unit","propName":"sys_name","propValueMask":"*","sortType":"sys_name"},"force":1,"flags":1,"from":0,"to":0}'
    result = wialon_api.call('core_search_items', params)

    wialon_api.core_logout()

    print str(result)
except WialonError as e:
    print str(e)

I get WialonError(Invalid input core_search_items (4)) error. When using Postman with this same params, I get the response which I expect.

I have also tried the following params, i.e. as python dict:

params = {
    "spec": {
        "itemsType":"avl_unit",
        "propName":"sys_name",
        "propValueMask":"*",
        "sortType":"sys_name"
    },
    "force":1,
    "flags":1,
    "from":0,
    "to":0
}

But I get the same result.

After studying the code, I can see that urlencode might be causing the problem, since it converts the following:

{
    'svc': 'core/search_items',
    'params': {
        "spec":{
            "itemsType":"avl_unit",
            "propName":"sys_name",
            "propValueMask":"*",
            "sortType":"sys_name"
        },
        "force":1,
        "flags":1,
        "from":0,
        "to":0
    },
    'sid': 'foo42'
}

to

params=%7B%27flags%27%3A+1%2C+%27force%27%3A+1%2C+%27spec%27%3A+%7B%27sortType%27%3A+%27sys_name%27%2C+%27itemsType%27%3A+%27avl_unit%27%2C+%27propName%27%3A+%27sys_name%27%2C+%27propValueMask%27%3A+%27%2A%27%7D%2C+%27to%27%3A+0%2C+%27from%27%3A+0%7D&svc=core%2Fsearch_items&sid=foo42

What am I doing wrong? or is there a bug in the library?

TypeError: call() got multiple values for argument 'action'

Hello,
First of all, I will give an example where the raise exception:

from wialon import Wialon
w_api = Wialon(token='...')
w_api.report_exec_report(...)
w_api.report_get_result_chart(attachmentIndex=0, **action**=0, width=800, height=600, autoScaleY=1, pixelFrom=15, pixelTo=750, 
flags=0x1)

Have exception:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/maxim/.local/lib/python3.8/site-packages/wialon/api.py", line 211, in get
    return self.call(action_name, *args, **kwargs)
TypeError: call() got multiple values for argument 'action'

Method report_get_result_chart have argument action (https://sdk.wialon.com/wiki/en/kit/remoteapi/apiref/report/get_result_chart)
But method Wialon.call also have argument action. Any API method call method Wialon.call, so we have name conflict.

I think the solution to the problem is: rename Wialon.call argument action to action_ or action_name

Thank you for the attention

Wrapper installation crashes

Hi!
I had a problem installing this module. I´m running Python 3.5.2 x64 on a Windows 10 Pro box.
Most likely I'm doing something wrong but I can't find the issue.
I tried to install it through pip install python-wialon but I've got the same error.

C:\Users\user\Desktop\python-wialon-1.1.0>python setup.py install
Traceback (most recent call last):
File "setup.py", line 3, in
import wialon
File "C:\Users\user\Desktop\python-wialon-1.1.0\wialon__init__.py", line 4, in
import flags
ImportError: No module named 'flags'

Thanks for your time and sorry for the inconvenience.

can't install version 1.1.6 , 1.1.5 on python 2.7 . Is it supported ?

pleasee help, getting the following error.

ERROR: Command errored out with exit status 1:
command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-QyZdg1/python-wialon/setup.py'"'"'; file='"'"'/tmp/pip-install-QyZdg1/python-wialon/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-zJvwt7
cwd: /tmp/pip-install-QyZdg1/python-wialon/
Complete output (9 lines):
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-install-QyZdg1/python-wialon/setup.py", line 3, in
import wialon
File "wialon/init.py", line 6, in
from .api import Wialon, WialonError
File "wialon/api.py", line 3, in
from builtins import str
ImportError: No module named builtins
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

ImportError: cannot import name 'Wialon' from 'wialon'

Running the boilerplate code results in error:

from wialon import Wialon, WialonError

try:
    wialon_api = Wialon()
    # old username and password login is deprecated, use token login
    result = wialon_api.token_login(token=<mytoken>)
    wialon_api.sid = result['eid']

    result = wialon_api.avl_evts()

    wialon_api.core_logout()
except WialonError as e:
    pass

ERROR:

Traceback (most recent call last):
  File "wialon-api-test.py", line 1, in <module>
    from wialon import Wialon, WialonError
ImportError: cannot import name 'Wialon' from 'wialon' (/Users/me/Library/Caches/pypoetry/virtualenvs/ffs-fPSGPQDn-py3.8/lib/python3.8/site-packages/wialon/__init__.py)

"AttributeError: 'HTTPMessage' object has no attribute 'getheader' " on token_login using python 3.4.3

I am trying to login using the following code using python 3.4.3:

from wialon.api import Wialon, WialonError
from wialon import flagsfrom wialon.api import Wialon, WialonError
from wialon import flags


wialon_api = Wialon()
result = wialon_api.token_login(token='XXXXX')

Getting below error:

Traceback (most recent call last):
File "", line 1, in
File "/home/admin/EM3GIS/EM3GIS/gisenv/lib/python3.4/site-packages/wialon/api.py", line 176, in get
return self.call(action_name, *args, **kwargs)
File "/home/admin/EM3GIS/EM3GIS/gisenv/lib/python3.4/site-packages/wialon/api.py", line 127, in call
return self.request(action, self.__base_api_url, all_params)
File "/home/admin/EM3GIS/EM3GIS/gisenv/lib/python3.4/site-packages/wialon/api.py", line 141, in request
content_type = response.info().getheader('Content-Type')
AttributeError: 'HTTPMessage' object has no attribute 'getheader'

pip install python-wialon gives "ImportError: No module named 'flags'"

Hi,

I'm using Python 3.5.2. When I ran pip install python-wialon I received the following error:

$ pip install python-wialon
Collecting python-wialon
  Downloading python-wialon-1.1.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/v0/phxxyfwd5p5gkzt466v9qjrh0000gn/T/pip-build-n0ouxwll/python-wialon/setup.py", line 3, in <module>
        import wialon
      File "/private/var/folders/v0/phxxyfwd5p5gkzt466v9qjrh0000gn/T/pip-build-n0ouxwll/python-wialon/wialon/__init__.py", line 4, in <module>
        import flags
    ImportError: No module named 'flags'

It seems like py-flags is a dependency. After I installed py-flags, the install for python-wialon worked.

Maybe py-flags can be added to setup.py?

thanks!

new token login

hello, could be possible to update the code for working with new login mechanism ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.