Ad Widget

Collapse

Python API Modules not working with 6.4

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michael.weber
    Senior Member
    • Nov 2015
    • 121

    #1

    Python API Modules not working with 6.4

    After Update to Zabbix Server 6.4 no Python Module is working. It does not matter if I am using token or username/password:
    pyzabbix.api.ZabbixAPIException: ('Error -32602: Invalid params., Not authorized.', -32602)
    Any idea?
    Already created a issue on most updated Python module, but no comment yet.
    Login not working - Error -32602: Invalid params., Not authorized.', -32602 · Issue users permissions problem · lukecyca/pyzabbix (github.com)​

  • chojin
    Member
    Zabbix Certified Specialist
    • Jul 2011
    • 64

    #2
    I'm seeing the same problem.
    After looking into the pyzabbix code; I see that they user the "Authorization: Bearer xxxx"-header method to authenticate.. As is documented in the Zabbix 6.4 API Documentation, noting that the "auth" parameter is deprecated in favor of the Authorization Bearer.

    So I tried manually both methods using curl..
    Code:
    curl --request POST --url 'http://zabbixserver/api_jsonrpc.php' --header 'Authorization: Bearer 5488f5b22f4ec4d028596deecc90d41a7bd26076f818f2d3f5be9596ce1a5da9' --header 'Content-Type: application/json' --data '{"jsonrpc": "2.0","method": "host.get","params": {"output": ["hostid","host"]},"id": 2}'
    But I also get
    Code:
    {"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"Not authorized."},"id":2}
    While
    Code:
    curl --request POST --url 'http://zabbixserver/api_jsonrpc.php' --header 'Content-Type: application/json' --data '{"jsonrpc": "2.0","method": "host.get","params": {"output": ["hostid","host"]},"id": 2,"auth": "5488f5b22f4ec4d028596deecc90d41a7bd26076f818f2d3f5be9596ce1a5da9"}'
    correctly returns the desired result:
    Code:
    {"jsonrpc":"2.0","result":[{"hostid":"14195","host":"icos"},{"hostid":"14207","host":"webdbprd"},{"hostid": ....
    So it looks to me that for some reason, despite the documentation claiming that we should now use the Authorization Bearer and "auth" being deprecated.. the bearer just doesn't work. (Above example is using an API token, but results are the same if I obtain a token using user.login method)​
    Last edited by chojin; 12-06-2023, 10:42.

    Comment

    • chojin
      Member
      Zabbix Certified Specialist
      • Jul 2011
      • 64

      #3
      I opened a bug report at Zabbix for it: ZBX-22952 API authentication using Authorization bearer header does not work

      Comment

      • michael.weber
        Senior Member
        • Nov 2015
        • 121

        #4
        Thank you very much!

        Comment

        • chojin
          Member
          Zabbix Certified Specialist
          • Jul 2011
          • 64

          #5
          I found adding
          Code:
          SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
          ​to the apache config solved the problem.
          It seems Apache by default does not pass the Authorization header.

          Comment

          • rons4
            Junior Member
            • Jan 2020
            • 15

            #6
            I ran into the same issue with the Zabbix appliance and I found this solution here. I tried adding the above line to .conf files where I thought Apache would read them, unfortunately without any success. Can anyone please tell me there to find (or add) the Apache config file to add the mentioned line?
            Thanks a lot.

            Comment

            • zabbix-user007
              Junior Member
              • Jan 2025
              • 25

              #7
              Originally posted by rons4
              I ran into the same issue with the Zabbix appliance and I found this solution here. I tried adding the above line to .conf files where I thought Apache would read them, unfortunately without any success. Can anyone please tell me there to find (or add) the Apache config file to add the mentioned line?
              Thanks a lot.

              was this ever answered for you? i am having the same issue

              Comment

              • michael.weber
                Senior Member
                • Nov 2015
                • 121

                #8
                I use the official python module https://blog.zabbix.com/python-zabbix-utils/27056/ now. This one is working without any modifications

                Comment

                • zabbix-user007
                  Junior Member
                  • Jan 2025
                  • 25

                  #9
                  Originally posted by michael.weber
                  I use the official python module https://blog.zabbix.com/python-zabbix-utils/27056/ now. This one is working without any modifications
                  thanks, Michael. I decided to create a new zabbix server and start from scratch or near scratch, anyway. the new server does not seem to have any issues connectig from CLI, although python would be fine, to..

                  cheers!

                  Comment

                  Working...