MCPcopy
hub / github.com/marimo-team/marimo / _try_fetch

Function _try_fetch

tests/_cli/test_cli.py:111–135  ·  view source on GitHub ↗
(
    port: int, host: str = "localhost", token: str | None = None
)

Source from the content-addressed store, hash-verified

109
110
111def _try_fetch(
112 port: int, host: str = "localhost", token: str | None = None
113) -> bytes | None:
114 import http.cookiejar
115
116 err: Exception | None = None
117 for _ in range(20):
118 try:
119 url = f"http://{host}:{port}"
120 if token is not None:
121 url = f"{url}?access_token={token}"
122 # The server 303-redirects `/?access_token=...` to strip the
123 # token from the URL, attaching the session cookie to the
124 # redirect. Use a cookie-aware opener so the follow-up request
125 # carries that cookie and lands on the authenticated page
126 # instead of the login screen.
127 opener = urllib.request.build_opener(
128 urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar())
129 )
130 return opener.open(url).read()
131 except Exception as e:
132 err = e
133 time.sleep(0.6)
134 print(f"Failed to fetch contents: {err}")
135 return None
136
137
138def _check_started(port: int, host: str = "localhost") -> bytes | None:

Calls 3

rangeFunction · 0.85
readMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…