noxrepo / pox

The POX network software platform
https://noxrepo.github.io/pox-doc/html/
Apache License 2.0
619 stars 470 forks source link

AttributeError: 'dict' object has no attribute 'iteritems' #261

Closed sappi13 closed 3 years ago

sappi13 commented 3 years ago

Code snippet where I feel would have some problems

  def _handle_expiration (self):
    # Called by a timer so that we can remove old items.
    empty = []
    for k,v in self.lost_buffers.iteritems():
      dpid,ip = k

      for item in list(v):
        expires_at,buffer_id,in_port = item
        if expires_at < time.time():
          # This packet is old.  Tell this switch to drop it.
          v.remove(item)
          po = of.ofp_packet_out(buffer_id = buffer_id, in_port = in_port)
          core.openflow.sendToDPID(dpid, po)
      if len(v) == 0: empty.append(k)  
    # Remove empty buffer bins
    for k in empty:
      del self.lost_buffers[k]

Error

sappi@sappi:~/Documents/pox$ sudo python3 ./pox.py forwarding.l3_editing
POX 0.7.0 (gar) / Copyright 2011-2020 James McCauley, et al.
WARNING:version:Support for Python 3 is experimental.
INFO:core:POX 0.7.0 (gar) is up.
Task <Timer 1 tid:2> caused an exception and was de-scheduled
Traceback (most recent call last):
  File "/home/sappi/Documents/pox/pox/lib/recoco/recoco.py", line 317, in cycle
    rv = t.execute()
  File "/home/sappi/Documents/pox/pox/lib/recoco/recoco.py", line 111, in execute
    return self.gen.send(v)
  File "/home/sappi/Documents/pox/pox/lib/recoco/recoco.py", line 1078, in run
    rv = self._callback(*self._args,**self._kw)
  File "/home/sappi/Documents/pox/pox/forwarding/l3_editing.py", line 120, in _handle_expiration
    for k,v in self.lost_buffers.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'
MurphyMc commented 3 years ago

This is exactly the same situation as #260.

Change it to .items() to make it Python3-friendly, or downgrade your POX to a Python2 version (fangtooth or earlier).

(Edit: Corrected my suggestion.)

sappi13 commented 3 years ago

Hi @MurphyMc

I'm pretty new to Python I didn't get where I should add .iter() to make it Python3-friendly?

MurphyMc commented 3 years ago

Instead of iteritems() it should just be items() in Python3.

See: http://python3porting.com/differences.html#dictionary-methods

Sorry, just noticed I said iter() above, when I meant items(). It's been a long day. ;)

sappi13 commented 3 years ago

No issues. Thanks.