adubkov/py-zabbix

Connection error

Greg-13 opened this issue · 4 comments

Hi,
I am sorry to bother you with that, but since we upgraded our zabbix (zabbix 3 to 3.2), we got the following error :

Error connection Zabbix :("Error -32700: Parse error, Invalid JSON. An error occurred on the server while parsing the JSON text. while sending {'params': {'password': 'MyPASS', 'user': 'MyUserZabbixAPI'}, 'jsonrpc': '2.0', 'method': 'user.login', 'id': '1'}", -32700)

Function :

def pyzabbix(alarme,valeur):
try:
# Create ZabbixAPI class instance
zapi = ZabbixAPI(url='https://My-zabbix.server/', user='MyUserZabbixAPI', password='MyPASS')
zapi.api_version()
print zapi
# Send metrics to zabbix trapper
packet = [
ZabbixMetric('MyHost', alarme, valeur)
]
result = ZabbixSender(use_config=True).send(packet)
print result
except Exception as e:
print "Error connection Zabbix :" + str(e)

Do you have an idea ?

Thank you ! 👍

I tried with Curl

data :

{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "MyUserZabbixAPI",
"password": "MyPASS"
},
"id": 1
}

Results
# curl -k -H "Content-Type: application/json" --data @data https://My-zabbix-server/api_jsonrpc.php {"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}

@Greg-13 did you ever figure this out? I'm stuck at the same place.

Hi, we are having the same issue with Zabbix 4.2 :(

I resolved it using Invoke-RestMethod instead of Invoke-WebRequest, and now api "understand" my json. (powershell code)
Curl never worked for me. is equivalent to to Invoke-WebRequest.
(I'm in Zabbix 4.2)