ValueError: invalid literal for int() with base 10: - Python
Hi All,
My python script appears to not like my system argv. I have a script which reads multicast data but rather than have a built in group wanted to use command line arguements. However when i run using the command line arguements i get thrown out with the below ValueError: invalid literal for int() with base 10: Script is below Code:
#!/usr/bin/python python watchMulticast.py 226.1.1.1 11130 Traceback (most recent call last): File "watchMulticast.py", line 7, in <module> MCAST_GRP = int(sys.argv[1]) ValueError: invalid literal for int() with base 10: '226.1.1.1' If i use the built in variable works like a charm. Any idea why it doesnt like my group im guessing it doesnt like the "." |
So you are saying that if you do the following it works just fine:
Code:
MCAST_GRP_VAL = '226.1.1.1' |
Quote:
Right so if i have the variable hard coded in the tool it works so as below : #MCAST_GRP = '226.1.1.1' #MCAST_PORT = 11130 Obviously no hash However when i use it as an user input through argv it doesnt like it MCAST_GRP = int(sys.argv[1]) MCAST_PORT = int(sys.argv[2]) Not entirely sure why it doesnt like it. Would rather not have to change a tool each time i want to look at a different group each time. |
MCAST_GRP = int(sys.argv[1])
why was that int put there? |
Quote:
Was an attempt to get it to work. If int isnt there the tool dies with below so was an attempt to get it to recognise the variable as an integer watchMulticast.py 226.1.1.1 11130 Traceback (most recent call last): File "watchMulticast.py", line 17, in <module> sock.bind((MCAST_GRP, MCAST_PORT)) # use MCAST_GRP instead of '' to listen only File "<string>", line 1, in bind TypeError: an integer is required |
port should be an integer, but argv1 should not.
|
You seemed to have missed my point. It does not matter if stored in a variable or called from the command line, but if you pass an ip address to int() you are going to get an error, hence my example
would also fail. As has been pointed out by pan64, you need to look at what arguments are required for the call to sock.bind. One of which needs to be an integer according to your error message, but it is flawed to think it means they both have to be integers. |
All times are GMT -5. The time now is 04:25 PM. |