Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASCII text executable, with CRLF line terminators

Good evening,

I'm currently enrolled in an introduction-course to python and have come across an issue that I haven't been able to solve. I'm sure it's a simple error somewhere in my code, but I haven't been able to find any questions on SO that solved my issue.

Strangely enough it compiles and runs fine when executing it from cygwin...

I'm getting this error while validating through 3rd party tests (that I don't have access to):

Python script, ASCII text executable, with CRLF line terminators

This is my code:

    height = float(input("What is the plane's elevation in metres? \r\n"))
    height = format(height * 3.28084, '.2f')

    speed = float(input("What is the plane's speed in km/h? \r\n"))
    speed = format(speed * 0.62137, '.2f')

    temperature = float(input("Finally, what is the temperature (in celsius) outside? \r\n"))
    temperature = format(temperature * (9/5) + 32, '.2f') 

    print("""\n########### OUTPUT ###########\n\nThe elevation is {feet} above the sea level, \n
you are going {miles} miles/h, \n
finally the temperature outside is {temp} degrees fahrenheit \n
########### OUTPUT ###########""".format(feet=height, miles=speed, temp=temperature)) 

And this is a cgi based on it (both are throwing the same error):

 #!/usr/bin/env python3
# -*- coding: utf-8 -*- 


# To write pagecontent to sys.stdout as bytes instead of string
import sys
import codecs


#Enable debugging of cgi-.scripts
import cgitb
cgitb.enable()


# Send the HTTP header
#print("Content-Type: text/plain;charset=utf-8")
print("Content-Type: text/html;charset=utf-8")
print("")


height = format(1100 * 3.28084, '.2f')

speed = format(1000 * 0.62137, '.2f')

temperature = format(-50 * (9/5) + 32, '.2f')


toPrint = """\n########### OUTPUT ###########\n\nThe elevation is {feet} above the sea level, \n
you are going {miles} miles/h, \n
finally the temperature outside is {temp} degrees fahrenheit \n
########### OUTPUT ###########"""

toPrint.format(feet=height, miles=speed, temp=temperature)

# Here comes the content of the webpage 
content = """<!doctype html>
<meta charset="utf-8">
<title>Min redovisnings-sida</title>
<pre>
<h1>Min Redovisnings-sida </h1>




</pre>

<body>
 {printer}
</body>

"""


# Write page content
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
sys.stdout.write(content.format(printer=toPrint))
like image 349
geostocker Avatar asked Oct 21 '25 02:10

geostocker


1 Answers

You need to convert CRLF to LF, to do so you can run this command:

dos2unix your_file

If you need to apply that to a specific folder content, use the below command inside your folder:

find . -type f -exec dos2unix {} \;

You need to install dos2unix package first:

sudo apt-get install dos2unix
like image 99
ettanany Avatar answered Oct 22 '25 14:10

ettanany