Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
-
from urllib.parse import urlencode, quote_plus
|
4 |
|
5 |
def forward_parameters(target_url, extra_params):
|
6 |
"""
|
@@ -11,6 +11,11 @@ def forward_parameters(target_url, extra_params):
|
|
11 |
:return: The response from the target URL.
|
12 |
"""
|
13 |
try:
|
|
|
|
|
|
|
|
|
|
|
14 |
# Construct the full URL with extra parameters
|
15 |
full_url = f"{target_url}?{urlencode(extra_params, quote_via=quote_plus)}"
|
16 |
response = requests.get(full_url) # Using GET request for simplicity
|
@@ -23,7 +28,7 @@ def forward_parameters(target_url, extra_params):
|
|
23 |
st.title('HTTPS Streamlit Parameters Forwarder')
|
24 |
|
25 |
# Correctly accessing the query parameters
|
26 |
-
params = st.query_params #
|
27 |
target_url = params.get('param1', [None])[0] # Extract the target URL
|
28 |
|
29 |
if target_url:
|
@@ -35,10 +40,10 @@ if target_url:
|
|
35 |
else:
|
36 |
st.error("No target URL provided.")
|
37 |
st.markdown("""
|
38 |
-
Please append `?param1=URL` to the query string in the address bar,
|
39 |
-
replacing `URL` with your desired target URL.
|
40 |
-
|
41 |
Example: `?param1=http://example.com¶m2=value`
|
42 |
-
|
43 |
This will forward `param2=value` to `http://example.com`.
|
44 |
""")
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
+
from urllib.parse import urlencode, quote_plus, urlparse
|
4 |
|
5 |
def forward_parameters(target_url, extra_params):
|
6 |
"""
|
|
|
11 |
:return: The response from the target URL.
|
12 |
"""
|
13 |
try:
|
14 |
+
# Ensure the target URL has a valid scheme
|
15 |
+
parsed_url = urlparse(target_url)
|
16 |
+
if not parsed_url.scheme:
|
17 |
+
return "Invalid URL: No scheme supplied. URLs must start with http:// or https://"
|
18 |
+
|
19 |
# Construct the full URL with extra parameters
|
20 |
full_url = f"{target_url}?{urlencode(extra_params, quote_via=quote_plus)}"
|
21 |
response = requests.get(full_url) # Using GET request for simplicity
|
|
|
28 |
st.title('HTTPS Streamlit Parameters Forwarder')
|
29 |
|
30 |
# Correctly accessing the query parameters
|
31 |
+
params = st.query_params # Access query parameters
|
32 |
target_url = params.get('param1', [None])[0] # Extract the target URL
|
33 |
|
34 |
if target_url:
|
|
|
40 |
else:
|
41 |
st.error("No target URL provided.")
|
42 |
st.markdown("""
|
43 |
+
Please append `?param1=URL` to the query string in the address bar,
|
44 |
+
replacing `URL` with your desired target URL.
|
45 |
+
|
46 |
Example: `?param1=http://example.com¶m2=value`
|
47 |
+
|
48 |
This will forward `param2=value` to `http://example.com`.
|
49 |
""")
|