Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path Conversion Issue in pathname2url Impacts Browser Launch on mingw-w64 #1474

Open
Kreijstal opened this issue Nov 19, 2024 · 0 comments
Open
Labels

Comments

@Kreijstal
Copy link

Kreijstal commented Nov 19, 2024

Description

When using Jupyter Server on mingw-w64 Python builds, the server fails to open the browser automatically. This issue is traced back to urllib.request.pathname2url, which produces malformed URLs when handling Windows paths with forward slashes. The malformed URLs (e.g., '///C://Users/...) prevent browsers from recognizing the paths correctly.

Steps to Reproduce

  1. Install mingw-w64-python-jupyter_server (via MSYS2).
  2. Start Jupyter Lab or Server with any typical command:
    jupyter lab
  3. Observe that the browser does not open, and the following URL is printed:
    file:///C://Users/.../runtime/jpserver-XXXXX-open.html
    
  4. Manually copy the URL into a browser and notice that it fails to open.
  5. Compare with the expected URL:
    file://C:/Users/.../runtime/jpserver-XXXXX-open.html
    

Analysis

from urllib.request import pathname2url as _pathname2url

pathname2url = _pathname2url

assembled_url = urljoin("file:", pathname2url(open_file))

Also reported on msys2-contrib/cpython-mingw#182

The root cause appears to be a bug in urllib.request.pathname2url, which mingw-w64 Python inherits. When converting paths, it doubles the forward slashes after the drive letter (C://) instead of normalizing to the expected format.

from urllib.request import pathname2url

print(pathname2url("C:/Users/example"))
# Output: '///C://Users/example' (Incorrect)
# Expected: '//C:/Users/example'

Expected Behavior

pathname2url should produce URLs in the format:

file://C:/Users/.../runtime/jpserver-XXXXX-open.html

This would allow browsers to open correctly, resolving the issue.

Context

  • Operating System: Windows (mingw-w64 environment, MSYS2)
  • Browser: Any modern browser
  • Jupyter Server version: 2.14.2-2
  • Python version: mingw-w64 Python (3.12.7)
@Kreijstal Kreijstal added the bug label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant