jtriley / pystun

A Python STUN client for getting NAT type and external IP
https://github.com/jtriley/pystun
MIT License
435 stars 154 forks source link

TypeError: 'dict_items' object is not subscriptable #35

Closed hktalent closed 2 years ago

hktalent commented 2 years ago

$ pip3 install pystun Collecting pystun Downloading pystun-0.1.0.tar.gz (6.3 kB) Preparing metadata (setup.py) ... done Building wheels for collected packages: pystun Building wheel for pystun (setup.py) ... done Created wheel for pystun: filename=pystun-0.1.0-py3-none-any.whl size=6481 sha256=49ffd31fb302af0bea1b41fbe0658dca4d143c1b044da2998a74f0b4139e3ba9 Stored in directory: Library/Caches/pip/wheels/6c/5c/b6/c718b0ecd36283aabd9ef70c1c5183ed4536f03c8565bd5e0a Successfully built pystun Installing collected packages: pystun

$ pystun

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/bin/pystun", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/stun/cli.py", line 51, in main
    nat_type, external_ip, external_port = stun.get_ip_info(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/stun/__init__.py", line 252, in get_ip_info
    nat_type, nat = get_nat_type(s, source_ip, source_port,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/stun/__init__.py", line 186, in get_nat_type
    _initialize()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/stun/__init__.py", line 93, in _initialize
    dictValToAttr.update({items[i][1]: items[i][0]})
TypeError: 'dict_items' object is not subscriptable
51pwn@51pwns-MacBook-Pro mywebapp $ pystun
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/bin/pystun", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/stun/cli.py", line 51, in main
    nat_type, external_ip, external_port = stun.get_ip_info(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/stun/__init__.py", line 252, in get_ip_info
    nat_type, nat = get_nat_type(s, source_ip, source_port,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/stun/__init__.py", line 186, in get_nat_type
    _initialize()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/stun/__init__.py", line 93, in _initialize
    dictValToAttr.update({items[i][1]: items[i][0]})
TypeError: 'dict_items' object is not subscriptable
z-jack commented 2 years ago

Use Python2 will resolve the issue.

PopMini commented 5 months ago

Fixed bug:


def _initialize():
    items = dictAttrToVal.items()
    for i in range(len(items)):
        tmp_item = {}
        tmp_item = { list(items)[i][1] : list(items)[i][0] }
        #dictValToAttr.update({items[i][1]: items[i][0]})
        dictValToAttr.update(tmp_item)
    items = dictMsgTypeToVal.items()
    for i in range(len(items)):
        tmp_item = {}
        tmp_item = { list(items)[i][1] : list(items)[i][0] }
        #dictValToMsgType.update({items[i][1]: items[i][0]})
        dictValToMsgType.update(tmp_item)