# Debug youtube_dl Error。OSError: ERROR: Unable to extract uploader id。 修正youtube_dl導致的Unable to extract uploader id 錯誤
###### tags: `Logging_debug`, youtube-dl` `pafy` ``
### 範例程式
程式在執行 ` url = pafy.new(url).getbest(preftype="mp4").url`時報錯
```python=
if 'youtube.com/' in str(url) or 'youtu.be/' in str(url): # if source is YouTube video
check_requirements(('pafy', 'youtube_dl'))
import pafy
url = pafy.new(url).getbest(preftype="mp4").url
```
### 錯誤訊息
```bash=
File "detect_pose.py", line 57, in detect
dataset = LoadStreams(source, img_size=imgsz, stride=stride)
File "/home/yunghui/yolov7/utils/datasets.py", line 288, in __init__
url = pafy.new(url).getbest(preftype="mp4").url
File "/home/yunghui/.local/lib/python3.8/site-packages/pafy/pafy.py", line 124, in new
return Pafy(url, basic, gdata, size, callback, ydl_opts=ydl_opts)
File "/home/yunghui/.local/lib/python3.8/site-packages/pafy/backend_youtube_dl.py", line 31, in __init__
super(YtdlPafy, self).__init__(*args, **kwargs)
File "/home/yunghui/.local/lib/python3.8/site-packages/pafy/backend_shared.py", line 97, in __init__
self._fetch_basic()
File "/home/yunghui/.local/lib/python3.8/site-packages/pafy/backend_youtube_dl.py", line 43, in _fetch_basic
raise IOError(str(e).replace('YouTube said', 'Youtube says'))
OSError: ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
```
==OSError: ERROR: Unable to extract uploader id==
- 按照指示更新到最新版(youtube_dl 2021.12.17)問題還是沒解決
- [x] 按照論壇查詢到的建議,改以`yt-dlp`做暫時性替代
### 修正方式
```
python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz
```
在terminal是跑看看
```
yt-dlp URL
```
This is a known issue, fixed in Master. For a temporary fix,
This installs tha master version. Run it through the command-line
where URL is the URL of the video you want. See yt-dlp --help for all options. It should just work without errors.
If you're using it as a module,
在.py檔中以module引入
```
import yt_dlp as youtube_dl
```
- [Error: Unable to extract uploader id - Youtube, Discord.py](https://stackoverflow.com/questions/75495800/error-unable-to-extract-uploader-id-youtube-discord-py)
#### 更改`pafy`內的`backend_youtube_dl.py`import youtube_dl的程式碼
檔案位置在 `/home/user/.local/lib/python3.8/site-packages/pafy/backend_youtube_dl.py`中
可用vim指令進去修改
```python=13
import yt_dlp as youtube_dl
```
- 修正yt_dl引發的`pafy/backend_youtube_dl.py`KeyError:
錯誤訊息:
```
File "/home/yunghui/.local/lib/python3.8/site-packages/pafy/backend_youtube_dl.py", line 54, in _fetch_basic
self._dislikes = self._ydl_info['dislike_count']
```
在 `class YtdlPafy(BasePafy):`內的
```python=54
# self._dislikes = self._ydl_info['dislike_count'] # fix
```