Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Apache's 'suexec issue' that wont let me run my python script

1,306 views
Skip to first unread message

Νικόλαος Κούρας

unread,
Jun 6, 2013, 12:04:27 AM6/6/13
to
i want to test a python script i made online online and i receive this message:

Code:
[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] suexec failure: could not open log file
[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] Premature end of script headers: koukos.py
[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] File does not exist: /home/nikos/public_html/500.shtml


when i tail -F /usr/local/apache/logs/error_log &

What this error means?

It appears that the effective user of the script does not have permission to open the log file
that the suexec call requires.
- fopen reported "permission denied", presumably on the logfile
- suexec, receiving the fopen "permission denied" error, reported "could not open log file"

These errors, in turn, seem to have prematurely terminated the script headers that i use in
koukos.py script, causing the koukos.py script to fail. This caused apache to report (with a generic
and inappropriate error message) that the shtml file that invokes the script failed.


root@nikos [/home/nikos/www/cgi-bin]# chmod 755 /var/log/httpd/suexec.log

root@nikos [/home/nikos/www/cgi-bin]# ls -l /var/log/httpd/suexec.log
-rwxr-xr-x 1 root apache 0 Jun 1 02:52 /var/log/httpd/suexec.log*

root@nikos [/home/nikos/www/cgi-bin]# chmod 755 /usr/local/apache/logs/error_log

root@nikos [/home/nikos/www/cgi-bin]# ls -l /usr/local/apache/logs/error_log
-rwxr-xr-x 1 root root 32414017 Jun 4 13:51 /usr/local/apache/logs/error_log*

root@nikos [/home/nikos/www/cgi-bin]# chown root:apache /usr/local/apache/logs/error_log
root@nikos [/home/nikos/www/cgi-bin]# ls -l /usr/local/apache/logs/error_log

-rwxr-xr-x 1 root apache 32414017 Jun 4 13:51 /usr/local/apache/logs/error_log*
root@nikos [/home/nikos/www/cgi-bin]#


Now the error i get whn trying to run my scgi script via browser is

root@nikos [/home/nikos/www/cgi-bin]# [Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] suexec failure: could not open log file
[Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] fopen: Permission denied
[Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] Premature end of script headers: koukos.py
[Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml


I just don't get it.....
I chmod'ed
i chown'ed

Reseaarchimg more of it:

The httpd processes are run by user 'nobody'. I have to change your httpd.conf to assign the correct user or change the owner of the log file to nobody.

root@nikos [~]# chown nobody:nobody /usr/local/apache/logs/error_log
root@nikos [~]# chown nobody:nobody /var/log/httpd/error_log

On httpd.conf looking for the following directives:
User nobody
Group nobody

implied that the httpd.conf is automatically generated by cPanel. Take a look:

# Defined in /var/cpanel/cpanel.config: apache_port
Listen 0.0.0.0:82
User nobody
Group nobody
ExtendedStatus On
ServerAdmin nikos...@gmail.com
ServerName nikos.superhost.gr
LogLevel warn

Trying to find a solution about my suexec issue i altered the httpd.conf file

root@nikos [~]# nano /usr/local/apache/conf/httpd.conf (altering user nobody to user root_

root@nikos [~]# service httpd restart
[Tue Jun 04 15:56:42 2013] [warn] module rpaf_module is already loaded, skipping
Syntax error on line 175 of /usr/local/apache/conf/httpd.conf:
Error:\tApache has not been designed to serve pages while\n\trunning as root. There are known race conditions that\n\twill allow any local user to read any file on the system.\n\tIf you still desire to serve pages as root then\n\tadd -DBIG_SECURITY_HOLE to the CFLAGS env variable\n\tand then rebuild the server.\n\tIt is strongly suggested that you instead modify the User\n\tdirective in your httpd.conf file to list a non-root\n\tuser.\n
root@nikos [~]#

Please help because no matter what i try i always receive the following when i http://superhost.gr/cgi-bin/koukos.py

[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] suexec failure: could not open log file
[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] Premature end of script headers: koukos.py

but the problem still remains.
suexec is not getting as far as running
the script.

Any ideas as to why iam havign this type of error?

J.O. Aho

unread,
Jun 6, 2013, 1:12:30 AM6/6/13
to
On 06/06/13 06:04, Νικόλαος Κούρας wrote:
> i want to test a python script i made online online and i receive this message:
>
> Code:
> [Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] suexec failure: could not open log file
> [Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] fopen: Permission denied
> [Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] Premature end of script headers: koukos.py
> [Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] File does not exist: /home/nikos/public_html/500.shtml

First of all, I don't use suexec myself, so if it's more than just file
permission, then I won't be much of help.


> What this error means?
>
> It appears that the effective user of the script does not have permission to open the log file
> that the suexec call requires.
> - fopen reported "permission denied", presumably on the logfile
> - suexec, receiving the fopen "permission denied" error, reported "could not open log file"
>
> These errors, in turn, seem to have prematurely terminated the script headers that i use in
> koukos.py script, causing the koukos.py script to fail. This caused apache to report (with a generic
> and inappropriate error message) that the shtml file that invokes the script failed.
>
>
> root@nikos [/home/nikos/www/cgi-bin]# chmod 755 /var/log/httpd/suexec.log
>
> root@nikos [/home/nikos/www/cgi-bin]# ls -l /var/log/httpd/suexec.log
> -rwxr-xr-x 1 root apache 0 Jun 1 02:52 /var/log/httpd/suexec.log*

The 755 will only give r and x privileges to the group and user, which
prevents them from writing. chmod 666 would most likely be a better
value, this makes all to be able to read and write.

Don't forget to check your path to the file too, it's not just enough
that the file is accessible for a user, the whole path to the file needs
to have the right permissions.

ls -ld /var/log/httpd
ls -ld /var/log

both of those needs to have xr for group and others (x allows a user to
get to the directory, r gives the user the ability to list files in the
directory).


--

//Aho

Νικόλαος Κούρας

unread,
Jun 6, 2013, 1:59:12 AM6/6/13
to
Τη Πέμπτη, 6 Ιουνίου 2013 8:12:30 π.μ. UTC+3, ο χρήστης J.O. Aho έγραψε:

> Don't forget to check your path to the file too, it's not just enough
> that the file is accessible for a user, the whole path to the file needs
> to have the right permissions.

> ls -ld /var/log/httpd
> ls -ld /var/log

> both of those needs to have xr for group and others (x allows a user to
> get to the directory, r gives the user the ability to list files in the
> directory).

ni...@superhost.gr [~]# ls -ld /var/log/
drwxr-xr-x 8 root root 4096 Jun 6 08:56 /var/log//

ni...@superhost.gr [~]# ls -ld /var/log/httpd
drwx------ 2 root root 4096 Jun 1 02:52 /var/log/httpd/

ni...@superhost.gr [~]# ls -l /var/log/httpd/suexec_log
/bin/ls: cannot access /var/log/httpd/suexec_log: Permission denied

ni...@superhost.gr [~]# ls -ld /usr/local/apache/logs/
drwxr-xr-x 2 root root 4096 Jun 6 08:14 /usr/local/apache/logs//

ni...@superhost.gr [~]# ls -ld /usr/local/apache/
drwxr-xr-x 17 root root 4096 May 16 22:46 /usr/local/apache//

ni...@superhost.gr [~]# ls -l /usr/local/apache/logs/suexec_log
-rw-rw-r-- 1 root apache 663769 Jun 5 04:37 /usr/local/apache/logs/suexec_log


Because i'm a bit confused both 'suexec' files need to change?
And what are the differences of them?
Why 2 'suexec' appear?
httpd != Apache ?



Νικόλαος Κούρας

unread,
Jun 6, 2013, 2:24:50 AM6/6/13
to
root@nikos [~]# chmod 755 /var/log
root@nikos [~]# chmod 755 /var/log/httpd
root@nikos [~]# chmod 666 /var/log/httpd/suexec.log

root@nikos [~]# chmod 755 /usr/local/apache
root@nikos [~]# chmod 755 /usr/local/apache/logs/
root@nikos [~]# chmod 666 /usr/local/apache/logs/error_log


and then execute via browser: http://superhost.gr/cgi-bin/koukos.py
still same error:

[Thu Jun 06 09:23:54 2013] [error] [client 79.103.41.173] suexec failure: could not open log file
[Thu Jun 06 09:23:54 2013] [error] [client 79.103.41.173] fopen: Permission denied
[Thu Jun 06 09:23:54 2013] [error] [client 79.103.41.173] Premature end of script headers: koukos.py



Richard Kettlewell

unread,
Jun 6, 2013, 4:03:04 AM6/6/13
to
Νικόλαος Κούρας <nikos...@gmail.com> writes:

> i want to test a python script i made online online and i receive this message:
>
> Code:
> [Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] suexec failure: could not open log file
> [Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] fopen: Permission denied
> [Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] Premature end of script headers: koukos.py
> [Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] File does not exist: /home/nikos/public_html/500.shtml
>
>
> when i tail -F /usr/local/apache/logs/error_log &
>
> What this error means?
>
> It appears that the effective user of the script does not have permission to open the log file
> that the suexec call requires.
> - fopen reported "permission denied", presumably on the logfile
> - suexec, receiving the fopen "permission denied" error, reported "could not open log file"
>
> These errors, in turn, seem to have prematurely terminated the script
> headers that i use in koukos.py script, causing the koukos.py script
> to fail. This caused apache to report (with a generic and
> inappropriate error message) that the shtml file that invokes the
> script failed.

The answers are the same as last time you asked. You have configured
your apache to use suexec when running koukos.py, but have not installed
suexec properly. You need to change at least one of these things.

Messing with the permissions of random logfiles will not help. Trying
to run Apache as root will not help.

--
http://www.greenend.org.uk/rjk/

Νικόλαος Κούρας

unread,
Jun 6, 2013, 6:49:40 AM6/6/13
to
Suexed wasnt installed by me, it was dne automatically by WHM.
I have tried anythigng i have been told by you or others and iam still presented the same error.

I didnt manually set suexec.

Νικόλαος Κούρας

unread,
Jun 6, 2013, 6:54:05 AM6/6/13
to
I have re-enabled 'suexec' and set cgi as default phphandler and then trying:

print( cookie )
print( '''Content-type: text/html; charset=utf-8\n''' )
print( message )

---------------------------------
ni...@superhost.gr [~/www/data/apps]# [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] suexec failure: could not open log file
[Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] fopen: Permission denied
[Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] Premature end of script headers: koukos.py

Even if dissable/enable suexec still this output error.

Νικόλαος Κούρας

unread,
Jun 6, 2013, 2:50:55 PM6/6/13
to
Plese do not give up on helping me.

Νικόλαος Κούρας

unread,
Jun 7, 2013, 3:24:07 AM6/7/13
to
Any other ideas guys?
I can output for you any command you ask me too, so you have a better understanding about this suexec thing.


I have checked the path to the error log file too, it's not just enough
that the file is accessible for a user, the whole path to the file needs
to have the right permissions.

ls -ld /var/log/httpd
ls -ld /var/log

both of those needs to have xr for group and others (as far as i know x allows a user to get into the directory, r gives the user the ability to list files in the directory).

So,

---------------------------------------------------
ni...@superhost.gr [~]# ls -ld /var/log/
drwxr-xr-x 8 root root 4096 Jun 6 08:56 /var/log//

root@nikos [~]# ls -ld /var/log/httpd/
drw-rw-rw- 2 root root 4096 Jun 6 22:03 /var/log/httpd//

root@nikos [~]# chmod 666 /var/log/httpd/
root@nikos [~]# ls -l /var/log/httpd/
total 8
drw-rw-rw- 2 root root 4096 Jun 6 22:03 ./
drwxr-xr-x 8 root root 4096 Jun 7 10:02 ../
-rwxr-xr-x 1 nobody nobody 0 Apr 14 08:57 error_log*
-rwxr-xr-x 1 nobody nobody 0 Jun 1 02:52 suexec_log*

----------------------------------------------------------

ni...@superhost.gr [~]# ls -ld /usr/local/apache/logs/
drwxr-xr-x 2 root root 4096 Jun 6 08:14 /usr/local/apache/logs//

ni...@superhost.gr [~]# ls -ld /usr/local/apache/
drwxr-xr-x 17 root root 4096 May 16 22:46 /usr/local/apache//

root@nikos [~]# chown nobody:nobody /usr/local/apache/logs/suexec_log

root@nikos [~]# ls -l /usr/local/apache/logs/suexec_log
-rw-rw-rw- 1 nobody nobody 678180 Jun 7 08:29 /usr/local/apache/logs/suexec_log
root@nikos [~]#

----------------------------------------------------------

Because i'm a bit confused both 'suexec' files need to change?
And what are the differences of them?
Why two 'suexec' logs appear?
httpd != Apache ?

J.O. Aho

unread,
Jun 7, 2013, 12:19:56 PM6/7/13
to
On 07/06/13 09:24, Νικόλαος Κούρας wrote:
> Any other ideas guys?
> I can output for you any command you ask me too, so you have a better understanding about this suexec thing.

There seems to be a thread
http://code.activestate.com/lists/python-list/643386/ so I won't go into
what you may have to do with suExec configurations.

Maybe you should just go back to default Apache configuration without
suExec and then follow a HOWTO which is for your distribution, do
exactly as they do and you will most likely be more successful.

A good thing to remember is to not edit your python files in a microsoft
windows machine, at least if you can't disable the return carriage in
the newline.
The default Apache log path for the distribution you use is
/var/log/httpd/

The /usr/local/apache/logs is due you either
A. Followed a howto and configured the path to be /usr/local/apache/logs
B. You installed a package with Apache which isn't from your
distribution or you built your own version.

An advice here, always try to use the version supplied by the
distribution, this will give you least problems.
If you built yourself or installed a 3rd party version of Apache, please
uninstall it, so you are sure you are using the right version.


> httpd != Apache ?

In some distributions Apache has been renamed to httpd, so they are the
same thing.

--

//Aho

Jasen Betts

unread,
Jun 8, 2013, 3:00:40 AM6/8/13
to
On 2013-06-07, J.O. Aho <us...@example.net> wrote:
> On 07/06/13 09:24, Νικόλαος Κούρας wrote:
>> Any other ideas guys?
>> I can output for you any command you ask me too, so you have a better understanding about this suexec thing.
>
> There seems to be a thread
> http://code.activestate.com/lists/python-list/643386/ so I won't go into
> what you may have to do with suExec configurations.
>
> Maybe you should just go back to default Apache configuration without
> suExec and then follow a HOWTO which is for your distribution, do
> exactly as they do and you will most likely be more successful.
>
> A good thing to remember is to not edit your python files in a microsoft
> windows machine, at least if you can't disable the return carriage in
> the newline.

Also the BOM, Win editors have a tendency to break scripts writen in
UTF-8 by adding some extra bytes before the shebang.

--
⚂⚃ 100% natural

Νικόλαος Κούρας

unread,
Jun 8, 2013, 11:39:48 AM6/8/13
to
Notepad edits all my python scripts as utf-8 without BOM and i also uplaoded using its npp+ plugin to the remote web host.

What is this BOM anyway. i see it many times? why soem editors use BOM? what;s its use?

J.O. Aho

unread,
Jun 8, 2013, 12:44:25 PM6/8/13
to
Notepad like carriage return "\r" in new lines, I suggest you run a
dos2unix after you uploaded the file.


> What is this BOM anyway. i see it many times? why soem editors use BOM? what;s its use?

Byte Order Mark, the file will start with the following three
characters (utf-8): 0xEF 0xBB 0xBF

If you display the text with iso-8859-1 or similar, you will see ""
in the beginning of the file.

The BOM is used to detect which type of UTF is used and it's by default
enabled in the microsoft world, while in the unix world you avoid it as
it's just extra crap when it comes to send data.


--

//Aho

Νικόλαος Κούρας

unread,
Jun 8, 2013, 1:37:55 PM6/8/13
to
Finally no suexec erros any more after chown all log files to nobody:nobody and their corresponding paths and permissions and everything.

Now the error has been transformed to:


[Fri Jun 07 10:48:47 2013] [error] [client 79.103.41.173] (2)No such file or directory: exec of '/home/nikos/public_html/cgi-bin/koukos.py' failed
[Fri Jun 07 10:48:47 2013] [error] [client 79.103.41.173] Premature end of script headers: koukos.py
[Fri Jun 07 10:48:47 2013] [error] [client 79.103.41.173] File does not exist: /home/nikos/public_html/500.shtml


but from interpretor view:

ni...@superhost.gr [~/www/cgi-bin]# python koukos.py
Set-Cookie: nikos=admin; expires=Mon, 02 Jun 2014 07:50:18 GMT; Path=/
Content-type: text/html; charset=utf-8

ΑΠΟ ΔΩ ΚΑΙ ΣΤΟ ΕΞΗΣ ΔΕΝ ΣΕ ΕΙΔΑ, ΔΕΝ ΣΕ ΞΕΡΩ, ΔΕΝ ΣΕ ΑΚΟΥΣΑ! ΘΑ ΕΙΣΑΙ ΠΛΕΟΝ Ο ΑΟΡΑΤΟΣ ΕΠΙΣΚΕΠΤΗΣ!!



(2)No such file or directory: exec of '/home/nikos/public_html/cgi-bin/koukos.py' failed

???? Can find what? koukos.py is there inside the cg-bin dir with 755 perms.

Νικόλαος Κούρας

unread,
Jun 8, 2013, 5:34:28 PM6/8/13
to
> It means that Apache is unable to find your cgi script. It's turning
> the url into a file path, but it can't find the file path. Sometimes
> Apache is configured to not follow symlinks.

Why every other python cgi script of mine that i run via browser doesnt produce this kind of error and only 'koukos.py' does?

> It's confusing too because you have two apaches installed. The system
> default one and the one that comes with cPanel.

Hi Michael, indeed they are too.
I wonder why cPanel deosnt use the default apache that came with the system and isntead complied its own.

anyway httpd.conf seems correct
==========
root@nikos [~]# cat /usr/local/apache/conf/httpd.conf | grep 'www'
# system refer to the documentation at: http://www.cpanel.net/support/docs/ea/ea3/customdirectives.html #
# system refer to the documentation at: http://www.cpanel.net/support/docs/ea/ea3/customdirectives.html #
ServerAlias www.varsa.gr
ServerAlias www.parking-byzantio.gr
ServerAlias www.cafebar-idea.gr
ServerAlias www.dauwin.gr
ServerAlias www.leonidasgkelos.com
ServerAlias www.mythosweb.gr
ServerAlias www.superhost.gr
ServerAlias www.panostech.gr
ServerAlias www.pdimou.gr
ServerAlias www.radio-klepsydra.com
ServerAlias www.cravendot.gr
ServerAlias www.ypsilandio.gr
ServerAlias www.oliveoils.mythosweb.gr
ServerAlias www.zimotirio.pdimou.gr

root@nikos [~]# cat /usr/local/apache/conf/httpd.conf | grep 'public_html'
UserDir public_html
DocumentRoot /home/akis/public_html
ScriptAlias /cgi-bin/ /home/akis/public_html/cgi-bin/
DocumentRoot /home/byzantio/public_html
ScriptAlias /cgi-bin/ /home/byzantio/public_html/cgi-bin/
DocumentRoot /home/cafebar/public_html
ScriptAlias /cgi-bin/ /home/cafebar/public_html/cgi-bin/
DocumentRoot /home/dauwin/public_html
ScriptAlias /cgi-bin/ /home/dauwin/public_html/cgi-bin/
DocumentRoot /home/gkelos/public_html
ScriptAlias /cgi-bin/ /home/gkelos/public_html/cgi-bin/
DocumentRoot /home/mythos/public_html
ScriptAlias /cgi-bin/ /home/mythos/public_html/cgi-bin/
DocumentRoot /home/nikos/public_html
ScriptAlias /cgi-bin/ /home/nikos/public_html/cgi-bin/
DocumentRoot /home/panos/public_html
ScriptAlias /cgi-bin/ /home/panos/public_html/cgi-bin/
DocumentRoot /home/pdimou/public_html
ScriptAlias /cgi-bin/ /home/pdimou/public_html/cgi-bin/
DocumentRoot /home/radio/public_html
ScriptAlias /cgi-bin/ /home/radio/public_html/cgi-bin/
DocumentRoot /home/tasos/public_html
ScriptAlias /cgi-bin/ /home/tasos/public_html/cgi-bin/
DocumentRoot /home/ypsiland/public_html
ScriptAlias /cgi-bin/ /home/ypsiland/public_html/cgi-bin/
DocumentRoot /home/mythos/public_html/oliveoils
ScriptAlias /cgi-bin/ /home/mythos/public_html/oliveoils/cgi-bin/
DocumentRoot /home/pdimou/public_html/zimotirio
ScriptAlias /cgi-bin/ /home/pdimou/public_html/zimotirio/cgi-bin/
root@nikos [~]#
=======================

Why every other python cgi script of mines doesnt prodice this error
and only 'koukos.py' does?

J.O. Aho

unread,
Jun 8, 2013, 6:08:59 PM6/8/13
to
On 08/06/13 23:34, Νικόλαος Κούρας wrote:

> Why every other python cgi script of mines doesnt prodice this error
> and only 'koukos.py' does?

Try:
dos2unix koukos.py

and then browse to the page again in your browser and see if it works or
not.

if it still don't work, try

awk '{if(NR==1)sub(/^\xef\xbb\xbf/,"");print}' koukos.py > koukos2.py &&
mv koukos.py koukos_old.py && mv koukos2.py koukos.py

if the file is the only python script which don't work, then it's either
bad newlines or bom.

--

//Aho

Jasen Betts

unread,
Jun 9, 2013, 12:40:32 AM6/9/13
to
It's the unicode byte order mark. a really bad idea in utf8 because
it doesn't work, and it breaks stuff, still some windows people want
their computers to do things automatically even it they occasionally
do the wrong thing for no reason.

--
⚂⚃ 100% natural

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

nagia....@gmail.com

unread,
Jun 9, 2013, 1:25:50 AM6/9/13
to
Τη Κυριακή, 9 Ιουνίου 2013 1:08:59 π.μ. UTC+3, ο χρήστης J.O. Aho έγραψε:
> On 08/06/13 23:34, Νικόλαος Κούρας wrote:

> Try:
> dos2unix koukos.py
> and then browse to the page again in your browser and see if it works or
> not.

i 'yum install dos2unix'
and then i
root@nikos [/home/nikos/www/cgi-bin]# dos2unix koukos.py
dos2unix: converting file koukos.py to UNIX format ...

and then by browsed it it worked!!!
You are great!
Its a mystery to me tough because every script i write into my Win8 OS i use Notepad++ to write/edit it, and i explicitly set it to utf-8 encoding without BOM.
so i wonder why specifically this script wanted a dos2unix tranformations.

Now, every time i have to do the same when i edit the script in win and uplaoded it on linux?

> if the file is the only python script which don't work, then it's either
> bad newlines or bom.



>The BOM is used to detect which type of UTF is used and it's by default
>enabled in the microsoft world, while in the unix world you avoid it as
>it's just extra crap when it comes to send data.

So, everythign we save in Microsoft Word using a BOM to help MS Office identify the type of unicode encoding used?

How does linux is able to detect the encoding of a file without the need of an extra string to tell it the encodings "brand" ?

J.O. Aho

unread,
Jun 9, 2013, 2:33:20 AM6/9/13
to
On 09/06/13 07:25, nagia....@gmail.com wrote:
> Τη Κυριακή, 9 Ιουνίου 2013 1:08:59 π.μ. UTC+3, ο χρήστης J.O. Aho έγραψε:
>> On 08/06/13 23:34, Νικόλαος Κούρας wrote:
>
>> Try:
>> dos2unix koukos.py
>> and then browse to the page again in your browser and see if it works or
>> not.
>
> i 'yum install dos2unix'
> and then i
> root@nikos [/home/nikos/www/cgi-bin]# dos2unix koukos.py
> dos2unix: converting file koukos.py to UNIX format ...
>
> and then by browsed it it worked!!!
> You are great!
> Its a mystery to me tough because every script i write into my Win8 OS i use Notepad++ to write/edit it, and i explicitly set it to utf-8 encoding without BOM.
> so i wonder why specifically this script wanted a dos2unix tranformations.

This isn't about BOM, it's about the carriage return which is part of
the microsoft end of line.

The microsoft eol: \r\n

The unix/linux eol: \n

So the \r in the eol makes your python script to not work.


> Now, every time i have to do the same when i edit the script in win and uplaoded it on linux?

To be on the safe side, I would recommend you did that, at least until
you upgrade to unix or linux on your desktop.


> So, everythign we save in Microsoft Word using a BOM to help MS Office identify the type of unicode encoding used?

sort of and not just limited to ms-word, but more or less all their
products.


> How does linux is able to detect the encoding of a file without the need of an extra string to tell it the encodings "brand" ?

This depends on the author of the application, some by config others try
to determine the encoding by looking on none 0-9A-Za-z characters, some
just assumes and others uses the locale.


--

//Aho

Νικόλαος Κούρας

unread,
Jun 9, 2013, 6:43:20 AM6/9/13
to
Thamnks J.O Aho

So, how from 'python koukos.py' script was interpreting correctly and from Chrome browser it gave that error that was unable to find itself?

Jasen Betts

unread,
Jun 9, 2013, 8:00:16 AM6/9/13
to
On 2013-06-09, J.O. Aho <us...@example.net> wrote:
> On 09/06/13 07:25, nagia....@gmail.com wrote:
>> Τη Κυριακή, 9 Ιουνίου 2013 1:08:59 π.μ. UTC+3, ο χρήστης J.O. Aho έγραψε:
>>> On 08/06/13 23:34, Νικόλαος Κούρας wrote:
>>
>>> Try:
>>> dos2unix koukos.py
>>> and then browse to the page again in your browser and see if it works or
>>> not.
>>
>> i 'yum install dos2unix'
>> and then i
>> root@nikos [/home/nikos/www/cgi-bin]# dos2unix koukos.py
>> dos2unix: converting file koukos.py to UNIX format ...
>>
>> and then by browsed it it worked!!!
>> You are great!
>> Its a mystery to me tough because every script i write into my Win8 OS i use Notepad++ to write/edit it, and i explicitly set it to utf-8 encoding without BOM.
>> so i wonder why specifically this script wanted a dos2unix tranformations.
>
> This isn't about BOM, it's about the carriage return which is part of
> the microsoft end of line.
>
> The microsoft eol: \r\n
>
> The unix/linux eol: \n
>
> So the \r in the eol makes your python script to not work.

No, it doesn't hurt python, just confuses the shebang

one work-around is

ln -s /usr/bin/python /usr/bin/python$'\015'


>> Now, every time i have to do the same when i edit the script in win and uplaoded it on linux?
>
> To be on the safe side, I would recommend you did that, at least until
> you upgrade to unix or linux on your desktop.

Or just edit it in wordpad (aka write) or one of the many notepad
replacements

>> So, everythign we save in Microsoft Word using a BOM to help MS Office identify the type of unicode encoding used?
>
> sort of and not just limited to ms-word, but more or less all their
> products.
>

there used to be an ASCII string you could put at the start of an ASCII
document to make windows render it in chinese symbols.

autodetect is impossible to get perfect.

>> How does linux is able to detect the encoding of a file without the need of an extra string to tell it the encodings "brand" ?
>
> This depends on the author of the application, some by config others try
> to determine the encoding by looking on none 0-9A-Za-z characters, some
> just assumes and others uses the locale.

easiest way is just use UTF-8 for all text, else you can use a
"codepage" locale if all your document match that locale everything
should be sweet.

Jasen Betts

unread,
Jun 9, 2013, 8:01:24 AM6/9/13
to
On 2013-06-09, Νικόλαος Κούρας <nikos...@gmail.com> wrote:
> Thamnks J.O Aho
>
> So, how from 'python koukos.py' script was interpreting correctly and from Chrome browser it gave that error that was unable to find itself?

what does './koukos.py' do ?

nagia....@gmail.com

unread,
Jun 10, 2013, 3:17:41 AM6/10/13
to
Τη Κυριακή, 9 Ιουνίου 2013 3:01:24 μ.μ. UTC+3, ο χρήστης Jasen Betts έγραψε:
> On 2013-06-09, Νικόλαος Κούρας <nikos...@gmail.com> wrote:
>
> > Thamnks J.O Aho
>
> >
>
> > So, how from 'python koukos.py' script was interpreting correctly and from Chrome browser it gave that error that was unable to find itself?
>
>
>
> what does './koukos.py' do ?

Tried to set a cookie using python 3.3.2 way of cookie-ing :)
But i wonder since i write all my scirpt with the use of Notepad++ setting explicitly utf-8 without BOM why the only failign was this script.
only efett dos2unix i ,made it run.

Martijn Lievaart

unread,
Jun 18, 2013, 4:19:44 AM6/18/13
to
On Sat, 08 Jun 2013 08:39:48 -0700, Νικόλαος Κούρας wrote:

> Notepad edits all my python scripts as utf-8 without BOM and i also
> uplaoded using its npp+ plugin to the remote web host.

Notepad has no plugins, Notepad+ is something different entirely.
Notepad+ is afaik able to edit utf-8, while Notepad can only edit files
in 8 and 16 bit unencoded characterset.

Also keep in mind that some transfer programs are smart enough to change
encoding as needed, but that seems not relevant to this case.

HTH,
M4
0 new messages