Problem loading module containing \r\n

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
udmicpy
Posts: 13
Joined: Tue Aug 15, 2017 3:47 pm

Problem loading module containing \r\n

Post by udmicpy » Tue Aug 15, 2017 4:44 pm

Dear all.

Last week I made my first steps with MicroPython and my ESP8266 12E.
I used ESPlorer on Windows 10 to upload code to the ESP8266.
All worked fine but when I tried to load the code of a simple webserver program as a module I got an error.

This is part of the code

......
def handleRequests(s):
cl, addr = s.accept()
print('client connected from', addr)
cl_file = cl.makefile('rwb', 0)
while True:
line = cl_file.readline()
if not line or line == b'\r\n': ### <<<--- THIS IS LINE 69 !!!
break
response = createHTML(getTemp())
cl.send(response)
cl.close()
......

The error was:
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
File "myModule.py", line 69
SyntaxError: invalid syntax

I had to mask the "\" bei "\\" to make the import of this code as a module work.

Is this a bug or did I make a mistake?

Thanks a lot in advance.

Best regards, Uwe

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Problem loading module containing \r\n

Post by Roberthh » Tue Aug 15, 2017 6:35 pm

There is no problem with \r or \n in MicroPython string handling. I guess that ESPlorer is the culprit, doing an additional escaping of \. Try another tool like rshell or ampy or Webrepl for uploading.

udmicpy
Posts: 13
Joined: Tue Aug 15, 2017 3:47 pm

Re: Problem loading module containing \r\n

Post by udmicpy » Thu Aug 17, 2017 8:27 am

Dear Robert,

thanks for your fast reply.
And indeed - it was a problem which I had only with ESPlorer.
Actually I'm using uPyLoader from this github project https://github.com/BetaRavener/uPyLoader
And with this tool I have no problems any more.

Bye, Uwe

Post Reply