(
port: int, host: str = "localhost", token: str | None = None
)
| 109 | |
| 110 | |
| 111 | def _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 | |
| 138 | def _check_started(port: int, host: str = "localhost") -> bytes | None: |
no test coverage detected
searching dependent graphs…