micropython error trail confusing me
-
Have you read that David Sedaris book 'Me talk pretty one day', there is a story in there about his troubles learning a new language, reminds me of my struggles with micropython, it certainly ain't pretty.
Here is the block of code from urequests
434 def close(self): 435 if self.raw: self.raw.close(); self.raw = None 436 self._cached = None 437 @property 438 def content(self): 439 if self._cached is None: 440 try: self._cached = self.raw.read() 441 finally: self.raw.close(); self.raw = None 442 return self._cached
and these are the errors
03/03 23:59:56 line 440 OSError: [Errno -76] MBEDTLS_ERR_NET_RECV_FAILED
03/03 23:59:56 line 441 AttributeError: NoneType object has no attribute closeI understand the first error. If there is no self.raw then you can't read it. But the second error confuses me self.raw.close presumably calls the close fn @ line 434. The first thing it does is check if self.raw exists before it tries to close it. So how come the attribute error?
-
Hi @kjm,
while I see that good timeout-functionality is very important to everyone out there (and probably for us as well), we haven't had the chance to care about these details yet. However, we will be happy to get any support for that ;].
With kind regards,
Andreas.
-
@andreas Interesting Andreas, I'll have a play with that.
Has your team thought about applying their talents to the problem of socket timeout after the DNS lookup in micropython? I did some experimenting after Peter's post in https://forum.pycom.io/topic/5547/power-saving-mode-psm-in-nb-iot-problems-with-reconnecting-after-deepsleep/2 In particular I played with his commented out lines where he had tried socket timeout, a topic dear to my heart.
I found:- short timeouts (0.1s) work & throw a TimeoutError as an exception. Although, interestingly, you can't capture it with an 'except TimeoutError'
- longer timeouts (5s) don't work and micropython will wait longer than the socket timeout for a server response.
-
Dear @kjm,
we took the chance to improve the
urequests
module according to your observations [1]. It has also been updated to be compatible with CPython.With kind regards,
Andreas.[1] https://github.com/daq-tools/pycopy-lib/blob/improve-urequests/urequests/urequests/init.py
-
The two lines [1] of the
content
property-method ofurequests
should probably be replaced with justself.close()
.[1] https://github.com/micropython/micropython-lib/blob/master/urequests/urequests.py#L22-L23
-
@andreas So whoever wrote urequests has the 'if self.raw' test in the wrong place? I need to check it before I call self.raw.close not inside the close() function?
-
@kjm said in micropython error trail confusing me:
So how come the attribute error?
@kjm said in micropython error trail confusing me:
line 441 AttributeError: NoneType object has no attribute close