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

struct.error: argument for 's' must be a bytes object #10

Open
VijayalakshmiSundaravaradhan opened this issue Feb 12, 2019 · 1 comment

Comments

@VijayalakshmiSundaravaradhan

net.py is my sample application to set the ip address of my eth0 interface. I get the following error while running the application.

Traceback (most recent call last):
File "net.py", line 119, in
inf.set_ip("192.168.7.59");
File "/usr/lib/python3.5/site-packages/pynetlinux/ifconfig.py", line 210, in set_ip
ifreq = struct.pack('16sH2s4s8s', self.name, AF_INET, '\x00'*2, ipbytes, '\x00'*8)
struct.error: argument for 's' must be a bytes object

Please help me with the error.

@samyabdellatif
Copy link

Hello, there @VijayalakshmiSundaravaradhan , I know this an old thread but since the package developer is not responding for a while , Just want to point this for reference for anyone who faces the same problem in the future .

I have been trying to build a simple GUI tool for managing network interfaces and came across this same error you mentioned.. after a little research I found it's because of the struct format that is passed to the function struct.pack('16sH2s4s8s' ...), you can find how this format works in details here . This module performs conversions between Python values and C structs represented as Python bytes objects.

these are the most used in the project
s -----> char[] | bytes char array in C is string for python so make sure the self.name is in byte
H ----> unsigned short | integer

so whenever you get this error go to the ifconfig.py and edit the line in the error

for example line 210 becomes

ifreq = struct.pack('16sH2s4s8s', bytes(self.name,'utf-8'), AF_INET, b'\x00'*2, ipbytes, b'\x00'*8)

and it worked for me this way

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

2 participants