Getting ValueError: invalid literal for int() with base 10: '' during conversion of string
<p>I have this TCP server that I want to be able to receive numbers (ints), and I'm having some difficulties solving some output from the program. It outputs what it should, but in addition it outputs some traceback with ValueError. How do I fix this?</p>

<pre><code>Traceback (most recent call last):   File "server.py", line 18, in
&lt;module&gt;
    data = int(conn.recv(BUFFER_SIZE).strip()); ValueError: invalid literal for int() with base 10: ''
</code></pre>

<p>What Im doing here is sending integers to the server:</p>

<pre><code>    data = int(conn.recv(BUFFER_SIZE).strip());

    foo = data + 1;

    if not data: break

    print "received data:", data
    print "\n foo:", foo
</code></pre>

<p>And that seems to work great, but besides the two prints I also get the traceback as mentioned :-/</p>

<p><strong>EDIT:</strong> </p>

<p>Thanks kindall for pointing it out. Since data (or the recv) could be empty, I just moved the logic under the if test and voila... :D</p>

<pre><code>        data = conn.recv(BUFFER_SIZE).strip();

        if not data: break

        command = int(data);
        foo = command + 1;
</code></pre>
