Can't read from serial device in Python
<p>I'm running a process using python GUI (using Tkinter). The process opens a thread that is supposed to read from a device connected via USB.</p>

<p>code example:</p>

<pre><code>self.com = serial.Serial()
x = self.com.read(size)
</code></pre>

<p>After reading the data, it is sent to a server.</p>

<p>Usually it works fine but sometimes I get an exception when trying to send the request to server:</p>

<blockquote>
  <p>if requests.codes.ok != responseObj.status_code: AttributeError:
  'dict' object has no attribute 'status_code'</p>
</blockquote>

<p>The problem is that I'm getting a <code>dict</code> type instead of <code>Response</code> object. </p>

<p>Could this be related to the thread that for some reason can't read the device output.</p>

<p>I tried to simulate the exception but it's hard to reproduce.
Any help with what could be the reason for this failure or ideas on how to reproduce it so I can debug it myself would be much appreciated.</p>