Page 1 of 1
evaluate "except OSError as er:"
Posted: Sat Jan 10, 2015 10:57 pm
by polygontwist
v1.3.8-43-gc114496
code from SD-Card. using WiFi CC3K.
How ca i find the OSError-Codes?
And how can I evaluate them?
i write a little WiFi-Server, i have Error: 57, 32, -57 or 1 and do not know what they mean.
Code: Select all
except OSError as er:
print (" OSError",er)
"er" is not String and not integer, an Objekt?
Re: evaluate "except OSError as er:"
Posted: Sun Jan 11, 2015 3:38 pm
by Damien
"er" is an exception object, and to get the value/argument of this you can use "er.args", or "er.args[0]" to get the first argument (which should be the errno in this case).
Which line of code raises the error?
Re: evaluate "except OSError as er:"
Posted: Sun Jan 11, 2015 5:23 pm
by polygontwist
Thank You. The one with the object I've been thinking, only found no documentation.
The Error is in this Line:
i have upload the projekt to:
https://github.com/polygontwist/HTTPServer
Re: evaluate "except OSError as er:"
Posted: Wed Jan 14, 2015 10:02 pm
by Damien
polygontwist wrote:Thank You. The one with the object I've been thinking, only found no documentation.
Well, that in particular is just how normal Python behaves
The Error is in this Line:
Ok, so it can raise an error if the socket is "in progress", or if there is a general error. That's not very helpful, unfortunately...
Here is my test TCP server and client code that works on my Adafruit CC3000 board (and also on my PC):
Code: Select all
import sys
if sys.platform == 'pyboard':
import pyb
import network
print('using CC3K driver')
print('creating')
nic = network.CC3K(pyb.SPI(2), pyb.Pin('Y5'), pyb.Pin('Y4'), pyb.Pin('Y3'))
print('created')
nic.connect('ssid', 'password')
print('connecting')
while not nic.isconnected():
pyb.delay(50)
print('connected')
print(nic.ifconfig())
def tcp_client():
import socket
addr = socket.getaddrinfo('micropython.org', 80)
print(addr)
for i in range(10):
s = socket.socket()
print(s)
print(s.connect(addr[0][-1]))
print(s.send(b'GET http://micropython.org/ks/test.html HTTP/1.0\r\n\r\n'))
while True:
data = s.recv(100)
if data:
print(len(data), data)
else:
break
s.close()
print('done')
def tcp_server():
import socket, time
s = socket.socket()
port = 8080
s.bind(('', port))
s.listen(5)
for i in range(10):
print("waiting for connection on port %d..." % port)
cl, addr = s.accept()
print(cl, addr)
data = cl.recv(20)
print(len(data), data)
cl.send(b'here is some data\r\nback for you!\r\n')
print('sent')
time.sleep(2)
cl.close()
s.close()
Re: evaluate "except OSError as er:"
Posted: Sat Jan 17, 2015 6:31 pm
by polygontwist
ok, i have rewrite my code. In principle, it is the same as your example.
I have in Line
data=csock.recv(128)
nevertheless the error "OSError -57" - after 4 connections
next Time in Line
"OSError: 57"
...
I hope you could improve the code. Otherwise, I must try yourself to communicate with the CC3k.
thanks