You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@guacamole.apache.org by michael böhm <ks...@gmx.net> on 2022/01/04 09:36:06 UTC
Fetch API-token not working in 1.4.0
Hello everyone
I upgraded to 1.4.0 and since then I cannot fetch the API token using this
example Python code:
######################################################
#!/usr/bin/python3
import sys
import json
import requests
import os
guac_host = "127.0.0.1"
guac_port = "8080"
guac_api_base = "http://{}:{}/guacamole/api/".format(guac_host, guac_port)
guac_username = "guacadmin"
guac_password = "***PASSWORD***"
os.environ['NO_PROXY'] = '127.0.0.1'
def get_guac_api_token(guac_username, guac_password):
api_url = "{0}tokens".format(guac_api_base)
text_body = "username={0}&password={1}".format(guac_username, guac_password)
response = requests.post(api_url, data=text_body.encode("utf-8"))
if not response.status_code == 200:
print(response.status_code)
print(response.content)
print("Error acquiring guacamole api-token. Aborting")
return(None)
json_response = response.content.decode()
json_response = json.loads(json_response)
return json_response["authToken"]
api_token = get_guac_api_token(guac_username, guac_password)
if api_token is None:
exit(1)
######################################################
Output is:
500
b'{"message":"Unexpected internal
error","translatableMessage":{"key":"APP.TEXT_UNTRANSLATED","variables":{"MESSAGE":"Unexpected
internal error"}},"statusCode":null,"expected":null,"type":"INTERNAL_ERROR"}'
Error acquiring guacamole api-token. Aborting
Has there anything changed from 1.3.0 where everything is working fine?
Thanks and best wishes
Michael
\--------------------------------------------------------------------- To
unsubscribe, e-mail: user-unsubscribe@guacamole.apache.org For additional
commands, e-mail: user-help@guacamole.apache.org
Aw: Re: Fetch API-token not working in 1.4.0
Posted by michael böhm <ks...@gmx.net>.
Hello Mike,
you were perfectly right.
When I add the Content-Type header, I can fetch the token via Python:
#################################################################
response = requests.post(api_url, data=text_body.encode("utf-8"),
headers={"Content-Type":"application/x-www-form-urlencoded"})
#################################################################
Thanks for your quick help.
Michael
**Gesendet:** Dienstag, 04. Januar 2022 um 11:03 Uhr
**Von:** "Mike Jumper" <mj...@apache.org>
**An:** user@guacamole.apache.org
**Betreff:** Re: Fetch API-token not working in 1.4.0
On Tue, Jan 4, 2022, 01:36 michael bohm <[ksk2@gmx.net](mailto:ksk2@gmx.net)>
wrote:
> Hello everyone
>
>
>
> I upgraded to 1.4.0 and since then I cannot fetch the API token using this
> example Python code:
>
>
>
> ######################################################
>
>
>
> #!/usr/bin/python3
>
> import sys
> import json
> import requests
> import os
>
>
>
> guac_host = "127.0.0.1"
> guac_port = "8080"
> guac_api_base = "http://{}:{}/guacamole/api/".format(guac_host, guac_port)
> guac_username = "guacadmin"
> guac_password = "***PASSWORD***"
>
>
>
> os.environ['NO_PROXY'] = '127.0.0.1'
>
>
>
> def get_guac_api_token(guac_username, guac_password):
> api_url = "{0}tokens".format(guac_api_base)
> text_body = "username={0}&password={1}".format(guac_username,
> guac_password)
> response = [requests.post](http://requests.post)(api_url,
> data=text_body.encode("utf-8"))
>
>
>
> if not response.status_code == 200:
> print(response.status_code)
> print(response.content)
> print("Error acquiring guacamole api-token. Aborting")
> return(None)
>
>
>
> json_response = response.content.decode()
> json_response = json.loads(json_response)
> return json_response["authToken"]
>
>
>
> api_token = get_guac_api_token(guac_username, guac_password)
>
>
>
> if api_token is None:
> exit(1)
>
>
>
> ######################################################
>
>
>
> Output is:
>
>
>
> 500
> b'{"message":"Unexpected internal
> error","translatableMessage":{"key":"APP.TEXT_UNTRANSLATED","variables":{"MESSAGE":"Unexpected
> internal
> error"}},"statusCode":null,"expected":null,"type":"INTERNAL_ERROR"}'
> Error acquiring guacamole api-token. Aborting
>
>
>
>
>
> Has there anything changed from 1.3.0 where everything is working fine?
Not directly, but a number of dependencies were upgraded, including Jersey.
It's possible the newer Jersey is more strict in its request handling.
If you can throw up a packet capture to see the actual content of the request,
I would compare that against the request sent by the browser during login to
see where the difference lies.
My guess is that you are missing a header in the Python code, presumably
"Content-Type: application/x-www-form-urlencoded".
\- Mike
\--------------------------------------------------------------------- To
unsubscribe, e-mail: user-unsubscribe@guacamole.apache.org For additional
commands, e-mail: user-help@guacamole.apache.org
Re: Fetch API-token not working in 1.4.0
Posted by Mike Jumper <mj...@apache.org>.
On Tue, Jan 4, 2022, 01:36 michael böhm <ks...@gmx.net> wrote:
> Hello everyone
>
> I upgraded to 1.4.0 and since then I cannot fetch the API token using this
> example Python code:
>
> ######################################################
>
> #!/usr/bin/python3
> import sys
> import json
> import requests
> import os
>
> guac_host = "127.0.0.1"
> guac_port = "8080"
> guac_api_base = "http://{}:{}/guacamole/api/".format(guac_host, guac_port)
> guac_username = "guacadmin"
> guac_password = "***PASSWORD***"
>
> os.environ['NO_PROXY'] = '127.0.0.1'
>
> def get_guac_api_token(guac_username, guac_password):
> api_url = "{0}tokens".format(guac_api_base)
> text_body = "username={0}&password={1}".format(guac_username,
> guac_password)
> response = requests.post(api_url, data=text_body.encode("utf-8"))
>
> if not response.status_code == 200:
> print(response.status_code)
> print(response.content)
> print("Error acquiring guacamole api-token. Aborting")
> return(None)
>
> json_response = response.content.decode()
> json_response = json.loads(json_response)
> return json_response["authToken"]
>
> api_token = get_guac_api_token(guac_username, guac_password)
>
> if api_token is None:
> exit(1)
>
> ######################################################
>
> Output is:
>
> 500
> b'{"message":"Unexpected internal
> error","translatableMessage":{"key":"APP.TEXT_UNTRANSLATED","variables":{"MESSAGE":"Unexpected
> internal
> error"}},"statusCode":null,"expected":null,"type":"INTERNAL_ERROR"}'
> Error acquiring guacamole api-token. Aborting
>
>
> Has there anything changed from 1.3.0 where everything is working fine?
>
Not directly, but a number of dependencies were upgraded, including Jersey.
It's possible the newer Jersey is more strict in its request handling.
If you can throw up a packet capture to see the actual content of the
request, I would compare that against the request sent by the browser
during login to see where the difference lies.
My guess is that you are missing a header in the Python code, presumably
"Content-Type: application/x-www-form-urlencoded".
- Mike