开发者

ValueError: invalid literal for int() with base 10: 'MSIE'

After I run my Python code on a big file of only HTTP headers, it gives me the above error. Any idea what that means?

Here is a piece of the code:

users = output.split(' ')[1]
accesses = 开发者_运维知识库output.split(' ')[3]
ave_accesses = int(accesses)/int(users)

Basically the 'users' are users who have accessed a website and 'accesses' are the total number of accesses by the users to that site. The 'ave_accesses' gives the number of accesses to that site by an average user. I hope this is enough to clear things, if not I can explain more.

thanks a lot, Adia.


It means that you are trying to convert a string to an integer, and the value of the string is 'MSIE'. The traceback will have a filename near this error and the line number (e.g., /my/module.py:123). Open the file and go to the line the error occurred, you should see a call to int() with a parameter. That parameter is probably supposed to be a number in string form, but it's not. You probably got your parsing code a little wrong, and fields were mixed up.

To track down the problem, use print statements around the code to see what is not working as expected. You can also use pdb.


I think, your header output is garbled. It is obviously looking for a number where it is find an string MSIE (which may be the value for User-Agent).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜