MIT-LCP / MIT-LCP/wfdb-python

Authentication handling in wfdb.io.dl_files, error 403

オープン
#568 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Jupyter Notebook
スター
853
フォーク
322
PR マージ指標
30日以内にマージされた PR はありません

説明

Context

I am trying to download specific files (subsets) from credentialed databases on PhysioNet using wfdb helper functions.

What I am trying to do is downloading selected files (not the entire dataset), e.g. :

from wfdb.io import dl_files
dl_files('mimiciv','data\\tmp',['hosp/patients.csv.gz'])

Stack trace

Created local base download directory: data\tmp
Downloading files...
Traceback (most recent call last):
  File "c:\Users\pa10198\Documents\_code\zarrow\dev.py", line 12, in <module>
    dl_files('mimiciv','data\\tmp',['hosp/patients.csv.gz'])
  File "C:\Users\pa10198\Documents\_code\zarrow\.venv\Lib\site-packages\wfdb\io\download.py", line 544, in dl_files
    pool.map(dl_pn_file, dl_inputs)
  File "C:\Users\pa10198\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\pool.py", line 367, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pa10198\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\pool.py", line 774, in get
    raise self._value
  File "C:\Users\pa10198\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pa10198\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\pool.py", line 48, in mapstar
    return list(map(*args))
           ^^^^^^^^^^^^^^^^
  File "C:\Users\pa10198\Documents\_code\zarrow\.venv\Lib\site-packages\wfdb\io\download.py", line 450, in dl_pn_file
    dl_full_file(url, local_file)
  File "C:\Users\pa10198\Documents\_code\zarrow\.venv\Lib\site-packages\wfdb\io\download.py", line 472, in dl_full_file
    content = readfile.read()
              ^^^^^^^^^^^^^^^
  File "C:\Users\pa10198\Documents\_code\zarrow\.venv\Lib\site-packages\wfdb\io\_url.py", line 580, in read
    result = b"".join(self._read_range(start, end))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pa10198\Documents\_code\zarrow\.venv\Lib\site-packages\wfdb\io\_url.py", line 473, in _read_range
    with RangeTransfer(self._current_url, req_start, req_end) as xfer:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pa10198\Documents\_code\zarrow\.venv\Lib\site-packages\wfdb\io\_url.py", line 167, in __init__
    self._parse_headers(method, self._response)
  File "C:\Users\pa10198\Documents\_code\zarrow\.venv\Lib\site-packages\wfdb\io\_url.py", line 213, in _parse_headers
    raise cls(
wfdb.io._url.NetFilePermissionError: 403 Error: Forbidden for url: https://physionet.org/files/mimiciv/3.1/hosp/patients.csv.gz

Remarks

  • I have the credentialed physionet account and access to the databases I request.
  • The same URL works in a browser after login and the file downloads successfully.

Questions

  • Is there any supported way to pass authentification when using dl_files or related functions, e.g. through env vars, config, etc.
  • If not, are there recommended workarounds (e.g., using cookies, tokens, or another library)? Ideally not leaving python and avoiding the multiplication of libraries within projects.

Feature idea

It would be very useful if wfdb supported:

  • authentication for credentialed MIMIC-IV (and similar datasets), and
  • partial downloads (which already works on the open datasets and seem supported structurally, but fail due to auth)

This would allow to avoid downloading entire large datasets and keep workflows within a single library.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

wfdb/io/download.py の dl_files、dl_pn_file、dl_full_file から始め、続いて wfdb/io/_url.py の RangeTransfer と _parse_headers を調べます。認証が必要な PhysioNet URL に対する 403 リクエストを再現し、アクセスがどのように処理されるかを追跡します。dl_files が認証が必要な選択したファイルを取得できる、文書化されたサポート対象の認証経路が実現すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
authentication, data
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。