I would like to parse all the parameters and query string of an URL rendered with voila python:
So far I have:
URL_BASE = os.environ.get('SCRIPT_NAME')
PARAMETERS = os.environ.get("QUERY_STRING")
print(f'{URL_BASE=}')
print(f'{PARAMETERS=}')
I would get:
URL_BASE='flyingcars.org/john/voila/render/shared/users/john/lrn_url.ipynb'
PARAMETERS='dossier=SA12345678&autorun=True&name=john'
but I have two questions:
a) how to get the rest of the parameters after # in the URL
b) Is there a standard library to get the query in form of a dictionary
What i tried:
I am trying to use cgi module in this way:
variables = cgi.FieldStorage()
variables2 = dict(cgi.FieldStorage())
ks = cgi.FieldStorage().keys()
print(f'{ks=}')
vs = cgi.FieldStorage().values() # error here
for key in cgi.FieldStorage().keys():
print(key)
print(fieldStorage[key].value) # error here
print(f'{variables=}')
print(f'{variables2=}')
this gives me an error in fieldStorage[key].value, and converting cgi.FieldStorage() into dict() does not work properly.
And these give errors:
print(fieldStorage[key].value)
And the previous line
fieldStorage().values()
Of I can hack around strings but there might be a straight way to get the variables in a dict with cgi. In cgi I can not get a way to get the parameters beyond the # symbol in the URL.
Thanks