Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to be updated to work with python 3.8 #599

Closed
NofelYaseen opened this issue Aug 2, 2023 · 2 comments
Closed

Need to be updated to work with python 3.8 #599

NofelYaseen opened this issue Aug 2, 2023 · 2 comments

Comments

@NofelYaseen
Copy link

I am following the README here: https://github.com/p4lang/PI/tree/main/proto/ptf

I get the error

======================================================================
ERROR: l3_host_fwd.FwdTest
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vagrant/PI/proto/ptf/base_test.py", line 668, in handle
    return f(*args, **kwargs)
  File "/home/vagrant/PI/proto/ptf/l3_host_fwd/test/l3_host_fwd.py", line 43, in runTest
    eg_port_str = stringify(eg_port, 2)
  File "/home/vagrant/PI/proto/ptf/base_test.py", line 69, in stringify
    decoded_s = s.decode("hex")
AttributeError: 'str' object has no attribute 'decode'

I am using the vm in
https://github.com/p4lang/tutorials/tree/master/vm-ubuntu-20.04

The vm uses python version 3.8. I am not sure which is expected for it work?

@antoninbas
Copy link
Member

I don't know where this code comes from, but it doesn't seem to be from this repo:

decoded_s = s.decode("hex")

The code is as follows:

h = '%x' % n
s = ('0'*(len(h) % 2) + h).zfill(length*2).decode('hex')
return s

However, this code is indeed invalid in Python3.
If someone wants to update the code and validate it with a recent version of Python, a PR would be very welcome.

@rst0git
Copy link
Member

rst0git commented Aug 3, 2023

I have opened a pull request to update the code (#600). The update is straightforward because stringify() implements the equivalent functionality of int.to_bytes in Python 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants