Ad Widget

Collapse

API call error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayfaar
    Junior Member
    • Aug 2018
    • 8

    #1

    API call error

    I have Cent OS 7 installed, Kernel: Linux 3.10.0-514.el7.x86_64, zabbix_server (Zabbix) 3.0.5., Python 2.7.5

    I writing python script to call api on zabbix server using requests module. When I run scrip I have a response from server with error code 404.

    My Script:

    # -*- coding:utf-8 -*-

    import requests
    import json


    def zabbixLogin(url, user, password):

    headers = {'Content-Type': 'application/json-rpc'}

    payload = {
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
    "user": user,
    "password": password
    },
    "id": 1,
    "auth": "null"
    }

    try:
    response = requests.post(url=url,
    headers=headers,
    data=json.dumps(payload))

    print(response.text)
    except Exception as e:
    raise e


    if __name__ == '__main__':
    url = 'http://192.168.100.10/zabbix/api_jsonrpc.php HTTP/1.1'
    user = 'user'
    password = 'pass'
    zabbixLogin(url, user, password)


    I tested this query usin curl and I have a reply but with sum error:

    ]$ curl -X POST -H "Content-type:application/json-rpc" -d @/home/user/mnt/zbx-con.json http://192.168.100.10/zabbix/api_jsonrpc.php HTTP/1.1
    {"jsonrpc":"2.0","result":"3.0.5","id":1}curl: (6) Could not resolve host: HTTP; Unknown error

  • Atsushi
    Senior Member
    • Aug 2013
    • 2028

    #2
    I think that "HTTP / 1.1" at the end of the command line is unnecessary.

    ex.
    Code:
    $ curl -X POST -H "Content-type:application/json-rpc" -d @/home/user/mnt/zbx-con.json http://192.168.100.10/zabbix/api_jsonrpc.php

    Comment

    Working...