strange python scripting error

nn pruebauno at latinmail.com
Fri Jul 24 10:45:21 EDT 2009


On Jul 23, 7:03 pm, Dave Angel <da... at ieee.org> wrote:
> Mark Tarver wrote:
> > I have a very strange error.  I have two test python files test.py and
> > python.py which contain the following code
>
> > #!/usr/bin/python
> > print "Content-type: text/html"
> > print
> > print "<html>"
> > print "<center>Hello, Linux.com!</center>"
> > print "</html>"
>
> > One file (test.py) works; you call it up and it shows a web page with
>
> > Hello, Linux.com
>
> > The other fails with a server configuration error.  Both are running
> > under Linux, same server, same permissions.  Running a character scan
> > shows that both files contain the same printable characters and are
> > therefore typographically identical.   They are absolutely the same.
>
> > The only hint at a difference I can see is that my ftp program says
> > the files are of unequal lengths.  test.py is 129 bytes long.
> > python.py 134 bytes long.
>
> > A zipped folder containing both files is at
>
> >www.lambdassociates.org/weird.zip
>
> > Any ideas welcome.
>
> > Mark
>
> Easiest explanation is that python.py has Windows-style newlines.  In
> other words, each line ends with 0d0a, rather than the Unix convention
> of 0a.
>
> If your server is Unix-based, it can't handle that first line, since it
> has an illegal character (0d) following the
>
> #!/usr/bin/python
>
> line.  Convert it to Unix line-endings.
>
> DaveA

Use dos2unix for conversion of the longer file and try again:

http://linux.about.com/od/commands/l/blcmdl1_dos2uni.htm



More information about the Python-list mailing list