AlexAplin / nndownload

Download and process links from Niconico (nicovideo.jp)
MIT License
223 stars 29 forks source link

TypeError: 'type' object is not subscriptable #114

Closed SCGabriel closed 2 years ago

SCGabriel commented 2 years ago

I try to use nndownload.py v1.11.2 in Kubuntu 20.04,but it returns errors.

nndownload.py -u user -p password --proxy socks5://192.168.1.99:32233/ --force-high-quality --dump-metadata --download-thumbnail https://www.nicovideo.jp/watch/sm38318426

Traceback (most recent call last):
  File "/usr/local/bin/nndownload.py", line 1668, in <module>
    def process_url_mo(session, url_mo: re.Match[AnyStr]):
TypeError: 'type' object is not subscriptable
python --version
Python 3.8.10
ls -alh /usr/bin/python*
lrwxrwxrwx 1 root root   24 12月  6 10:19 /usr/bin/python -> /etc/alternatives/python
lrwxrwxrwx 1 root root    9 3月  13  2020 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3.6M 3月   8  2021 /usr/bin/python2.7
lrwxrwxrwx 1 root root   33 3月   8  2021 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root   16 3月  13  2020 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root    9 5月  17  2021 /usr/bin/python3 -> python3.8
-rwxr-xr-x 1 root root 5.3M 9月  29 00:10 /usr/bin/python3.8
lrwxrwxrwx 1 root root   33 9月  29 00:10 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config
lrwxrwxrwx 1 root root   16 3月  13  2020 /usr/bin/python3-config -> python3.8-config
lrwxrwxrwx 1 root root   14 4月  15  2020 /usr/bin/python-config -> python2-config
AlexAplin commented 2 years ago

Maybe a type hint issue, I think it should be:

from typing import Match
[...]
def process_url_mo(session, url_mo: Match):
romanrm commented 2 years ago

AlexAplin added the bug label 23 days ago

...and?

Just faced the same error, and almost abandoned the program, thinking it probably requires too new python3 (which my distro still doesn't have). But after changing the code as suggested, it at least appears to launch without errors, did not test the operation yet.

--- nndownload.py.orig  2022-01-12 02:16:51.896783064 +0500
+++ nndownload.py   2022-01-12 02:17:26.073213438 +0500
@@ -17,7 +17,7 @@
 import time
 import traceback
 import xml.dom.minidom
-from typing import AnyStr, List
+from typing import AnyStr, List, Match

 import aiohttp
 import requests
@@ -1665,7 +1665,7 @@
     return session

-def process_url_mo(session, url_mo: re.Match[AnyStr]):
+def process_url_mo(session, url_mo: Match):
     """Dispatches URL to the appropriate function."""

     url_id = url_mo.group(5)