• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Python API authentication

Scheduled Pinned Locked Moved
General Problems
2
3
472
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    Roach
    last edited by Jul 16, 2021, 8:18 AM

    Hi,

    Going nuts over here, maybe overlooking a setting ? i have no idea.

    I enabled the API at settings, copied the API key.
    I enabled the API on fog user account, copied the API key.

    I use this in the following script i took from somewhere over here and imputted my API keys:

    import requests

    usertoken=‘MTM3OWM1YjczZjI3OGZlNmVjNjk0MWQwYTUzOTljNTFjOTc0YmE0OWRiMjQ5MzhhOGE0ZGM4ODRjZjFkOWI2MzI3NjNlYzMxYTY4MWJhNjEzOTFmMWY3OTEwMDJmNTUwM2Q1NTNjMjlhZTA5NmQxxxxxxllYjdjNDQ2YTBmNDU=’
    apitoken=‘NjhmN2VkNmFiZWVmZGQ4NjNhNGYyMzAwYmEyZGY4MWMwYzdhZGFmZjQyZjI0Yzc0Mjc1NzNmYWE1xxxE2YjZlODJhNjNhZmFiMzg1NGU3NmM1MjQzMDc4M2FjYTU0NGExMWQ2NWQ4ODEzOTgzMGRkNGY5MWJlZjQ=’
    headers = {‘fog-user-token’: usertoken, ‘fog-api-token’:apitoken }
    r = requests.get(‘http://x.x.x.x/fog/task/current’, params=headers)

    print(r.url)

    Im getting back : <Response [403]>

    is there a hidden setting somewhere ? i dont get it.

    T 1 Reply Last reply Jul 16, 2021, 11:45 AM Reply Quote 0
    • T
      Tom Elliott @Roach
      last edited by Tom Elliott Jul 16, 2021, 5:46 AM Jul 16, 2021, 11:45 AM

      @roach We don’t manage the FOG Python stuff, or is this your own personal script that you bbuilt?

      You can test the authentication process by opening a terminal to the FOG Server directly (replace url information to use localhost instead of the FQDN or IP address just for simplicity sake.

      Using curl to simulate a request:

      curl -H 'fog-api-token: NjhmN2VkNmFiZWVmZGQ4NjNhNGYyMzAwYmEyZGY4MWMwYzdhZGFmZjQyZjI0Yzc0Mjc1NzNmYWE1xxxE2YjZlODJhNjNhZmFiMzg1NGU3NmM1MjQzMDc4M2FjYTU0NGExMWQ2NWQ4ODEzOTgzMGRkNGY5MWJlZjQ=' \
      -H 'fog-user-token: MTM3OWM1YjczZjI3OGZlNmVjNjk0MWQwYTUzOTljNTFjOTc0YmE0OWRiMjQ5MzhhOGE0ZGM4ODRjZjFkOWI2MzI3NjNlYzMxYTY4MWJhNjEzOTFmMWY3OTEwMDJmNTUwM2Q1NTNjMjlhZTA5NmQxxxxxxllYjdjNDQ2YTBmNDU=' \
      -X GET \
      http://localhost/fog/task/current
      

      If this is still getting 403 you could try swapping the user-token and api-token (maybe you copied and pasted in the wrong spots?)

      I’d start with this to see if it helps you out. Once this is complete, I would highly suggest “reset tokens” for both the API and User as you’re publically shared this.

      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

      Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

      Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

      R 1 Reply Last reply Jul 16, 2021, 12:29 PM Reply Quote 0
      • R
        Roach @Tom Elliott
        last edited by Jul 16, 2021, 12:29 PM

        @tom-elliott Hi, thanks for the reply.

        Im getting the following errors : in CMD :

        curl: (6) Could not resolve host: NjhmN2VkNmFiZWVmZGQ4NjNhNGYyMzAwYmEyZGY4MWMwYzdhZGFmZjQyZjI0Yzc0Mjc1NzNmYWE1MjVlMzBjODM5MTE2YjZlODJhNjNhZmFiMzg1NGU3NmM1MjQzMDc4M2FjYTU0NGExMWQ2NWQxxxxMWJlZjQ’
        curl: (6) Could not resolve host: MTM3OWM1YjczZjI3OGZlNmVjNjk0MWQwYTUzOTljNTFjOTc0YmE0OWRiMjQ5MzhhOGE0ZGM4ODRjZjFkOWI2MzI3NjNlYzMxYTY4MWJhNjEzOTFmMWY3OTEwMDJmNTUwM2Q1NTNjMjlhZTA5NmQ3xxxxNDU’

        and in powershell console :

        Invoke-WebRequest : Cannot bind parameter ‘Headers’. Cannot convert the "fog-api-token:

        But nevermind, thanks for the support but im throwing in the towel. Guess this is just 1 of those things thats to complicated for me. Hoped it was simple, but im getting errors left and right. Thanks for your time. Dont waste anymore on me 🙂

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          3/3
          Last post

        157

        Online

        12.1k

        Users

        17.3k

        Topics

        155.3k

        Posts
        Copyright © 2012-2024 FOG Project