Python API authentication
-
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.
-
@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.
-
@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