Sign in to follow this  
Guest Luckxander

Dúvida

Recommended Posts

Guest Luckxander

Estou tentando rodar o programa abaixo, mas quando faço o test http no browser, não funciona.

Tenho o Apache(c:\Apache) instalado na raiz C.

Tenho o Python (c:\Python25) instalado na raiz C.

Simplesmente não roda, alguém me ajuda ?

>>> #!/Python25/python

# hora.py - CGI que exibe a hora local do servidor

from time import time, localtime

print 'Content-type: text/html'

print

h, m, s = localtime(time())[3:6]

print '<HTML><BODY>'

print '<H1>Hora: %02d:%02d:%02d</H1>' % (h, m, s)

print '<P>* de acordo com o relógio interno deste servidor</P>'

print '</BODY></HTML>'

Share this post


Link to post
Share on other sites

Veja as mensagens que estão no arquivo error.log e poste aqui.

>>> #!/Python25/python
No Windows a primeira linha do programa deve ser:
#!c:/Python25/python.exe

Com qual endereço você está tentando executar o programa no navegador? Este é o único programa que não funciona?

No Windows as vezes o Apache escuta na porta 8080, neste caso tente:

http://localhost:8080/cgi-bin/meu_programa.py

Em qual diretório está o programa? cgi-bin?

Share this post


Link to post
Share on other sites
Guest Luckxander

Na verdade nenhum dos programas estão funcionando, até scripts que peguei pronto e já estão testados.

Os programas estão no diretório Apache/Apache2/cgi-bin

Troquei a extensão

#! /Python25/python

pela

#! c:/Python25/python.exe

mas não adiantou, também tentei rodar pelo DOS mas não deu.

Imagino que tenha algum caminho que devo modificar mas sou novo em Python...

No browser tentei o localhost com o nome do arquivo e não deu,

depois tentei como você indicou para windows, também não deu.

Share this post


Link to post
Share on other sites
Na verdade nenhum dos programas estão funcionando, até scripts que peguei pronto e já estão testados.

Neste caso verifique se o Apache está rodando. Poste o error.log como eu sugeri no post anterior.

Troquei a extensão

#! /Python25/python

pela

#! c:/Python25/python.exe

Você está deixando um espaço entre "!" e "c". Não sei se faz diferença, mas na hora do sufoco é melhor não dar chance para o azar.

também tentei rodar pelo DOS mas não deu.

Se você abrir uma janela com o DOS e digitar python o que acontece?

Para abrir uma janela DOS configurada para o Python: Iniciar -> Programas -> Python -> Python (command lIne)

Share this post


Link to post
Share on other sites
Guest Luckxander

Arrumei o espaço entre os caracteres e não mudou nada.

Quando abri no DOS e digitei python, usando o caminho que você sugeriu, apareceu:

Traceback <most recent call last>:

File "<stdin>", line 1, in <module>

NameError: name 'python" is not defined

Testei o Apache, usando http://127.0.0.1/ e apareceu a página confirmando que o servidor

está correto.

Encontrei no Apache a pasta logs, com um arquivo txt chamado error, que tinha o seguinte conteúdo:

[Thu Oct 19 17:27:57 2006] [notice] Apache/2.0.58 (Win32) configured -- resuming normal operations

[Thu Oct 19 17:27:57 2006] [notice] Server built: Apr 29 2006 17:47:10

[Thu Oct 19 17:27:57 2006] [notice] Parent: Created child process 3988

[Thu Oct 19 17:27:58 2006] [notice] Child 3988: Child process is running

[Thu Oct 19 17:27:58 2006] [notice] Child 3988: Acquired the start mutex.

[Thu Oct 19 17:27:58 2006] [notice] Child 3988: Starting 250 worker threads.

[Thu Oct 19 18:14:23 2006] [notice] Parent: Received shutdown signal -- Shutting down the server.

[Thu Oct 19 18:14:23 2006] [notice] Child 3988: Exit event signaled. Child process is ending.

[Thu Oct 19 18:14:24 2006] [notice] Child 3988: Released the start mutex

[Thu Oct 19 18:14:25 2006] [notice] Child 3988: Waiting for 250 worker threads to exit.

[Thu Oct 19 18:14:25 2006] [notice] Child 3988: All worker threads have exited.

[Thu Oct 19 18:14:25 2006] [notice] Child 3988: Child process is exiting

[Thu Oct 19 18:14:25 2006] [notice] Parent: Child process exited successfully.

[Thu Oct 19 22:12:11 2006] [notice] Apache/2.0.58 (Win32) configured -- resuming normal operations

[Thu Oct 19 22:12:11 2006] [notice] Server built: Apr 29 2006 17:47:10

[Thu Oct 19 22:12:11 2006] [notice] Parent: Created child process 1552

[Thu Oct 19 22:12:11 2006] [notice] Child 1552: Child process is running

[Thu Oct 19 22:12:11 2006] [notice] Child 1552: Acquired the start mutex.

[Thu Oct 19 22:12:11 2006] [notice] Child 1552: Starting 250 worker threads.

[Thu Oct 19 22:53:24 2006] [notice] Parent: Received restart signal -- Restarting the server.

[Thu Oct 19 22:53:24 2006] [notice] Child 1552: Exit event signaled. Child process is ending.

[Thu Oct 19 22:53:24 2006] [notice] Apache/2.0.58 (Win32) configured -- resuming normal operations

[Thu Oct 19 22:53:24 2006] [notice] Server built: Apr 29 2006 17:47:10

[Thu Oct 19 22:53:24 2006] [notice] Parent: Created child process 620

[Thu Oct 19 22:53:25 2006] [notice] Child 620: Child process is running

[Thu Oct 19 22:53:25 2006] [notice] Child 620: Acquired the start mutex.

[Thu Oct 19 22:53:25 2006] [notice] Child 620: Starting 250 worker threads.

[Thu Oct 19 22:53:25 2006] [notice] Child 1552: Released the start mutex

[Thu Oct 19 22:53:26 2006] [notice] Child 1552: Waiting for 250 worker threads to exit.

[Thu Oct 19 22:53:26 2006] [notice] Child 1552: All worker threads have exited.

[Thu Oct 19 22:53:26 2006] [notice] Child 1552: Child process is exiting

[Thu Oct 19 22:58:27 2006] [notice] Parent: Received restart signal -- Restarting the server.

[Thu Oct 19 22:58:27 2006] [notice] Child 620: Exit event signaled. Child process is ending.

[Thu Oct 19 22:58:27 2006] [notice] Apache/2.0.58 (Win32) configured -- resuming normal operations

[Thu Oct 19 22:58:27 2006] [notice] Server built: Apr 29 2006 17:47:10

[Thu Oct 19 22:58:27 2006] [notice] Parent: Created child process 1836

[Thu Oct 19 22:58:27 2006] [notice] Child 1836: Child process is running

[Thu Oct 19 22:58:28 2006] [notice] Child 1836: Acquired the start mutex.

[Thu Oct 19 22:58:28 2006] [notice] Child 620: Released the start mutex

[Thu Oct 19 22:58:28 2006] [notice] Child 1836: Starting 250 worker threads.

[Thu Oct 19 22:58:29 2006] [notice] Child 620: Waiting for 250 worker threads to exit.

[Thu Oct 19 22:58:29 2006] [notice] Child 620: All worker threads have exited.

[Thu Oct 19 22:58:29 2006] [notice] Child 620: Child process is exiting

[Thu Oct 19 22:59:57 2006] [notice] Parent: Received shutdown signal -- Shutting down the server.

[Thu Oct 19 22:59:57 2006] [notice] Child 1836: Exit event signaled. Child process is ending.

[Thu Oct 19 22:59:58 2006] [notice] Child 1836: Released the start mutex

[Thu Oct 19 22:59:59 2006] [notice] Child 1836: Waiting for 250 worker threads to exit.

[Thu Oct 19 22:59:59 2006] [notice] Child 1836: All worker threads have exited.

[Thu Oct 19 22:59:59 2006] [notice] Child 1836: Child process is exiting

[Thu Oct 19 22:59:59 2006] [notice] Parent: Child process exited successfully.

[Thu Oct 19 23:00:05 2006] [notice] Apache/2.0.58 (Win32) configured -- resuming normal operations

[Thu Oct 19 23:00:05 2006] [notice] Server built: Apr 29 2006 17:47:10

[Thu Oct 19 23:00:05 2006] [notice] Parent: Created child process 240

[Thu Oct 19 23:00:05 2006] [notice] Child 240: Child process is running

[Thu Oct 19 23:00:05 2006] [notice] Child 240: Acquired the start mutex.

[Thu Oct 19 23:00:05 2006] [notice] Child 240: Starting 250 worker threads.

[Thu Oct 19 23:42:21 2006] [error] [client 127.0.0.1] File does not exist: C:/Apache/Apache2/htdocs/hora.py

[Fri Oct 20 10:51:46 2006] [notice] Apache/2.0.58 (Win32) configured -- resuming normal operations

[Fri Oct 20 10:51:46 2006] [notice] Server built: Apr 29 2006 17:47:10

[Fri Oct 20 10:51:46 2006] [notice] Parent: Created child process 1404

[Fri Oct 20 10:51:46 2006] [notice] Child 1404: Child process is running

[Fri Oct 20 10:51:46 2006] [notice] Child 1404: Acquired the start mutex.

[Fri Oct 20 10:51:46 2006] [notice] Child 1404: Starting 250 worker threads.

[Fri Oct 20 11:11:45 2006] [notice] Parent: Received restart signal -- Restarting the server.

[Fri Oct 20 11:11:45 2006] [notice] Child 1404: Exit event signaled. Child process is ending.

[Fri Oct 20 11:11:45 2006] [notice] Apache/2.0.58 (Win32) configured -- resuming normal operations

[Fri Oct 20 11:11:45 2006] [notice] Server built: Apr 29 2006 17:47:10

[Fri Oct 20 11:11:45 2006] [notice] Parent: Created child process 3036

[Fri Oct 20 11:11:45 2006] [notice] Child 3036: Child process is running

[Fri Oct 20 11:11:46 2006] [notice] Child 1404: Released the start mutex

[Fri Oct 20 11:11:46 2006] [notice] Child 3036: Acquired the start mutex.

[Fri Oct 20 11:11:46 2006] [notice] Child 3036: Starting 250 worker threads.

[Fri Oct 20 11:11:47 2006] [notice] Child 1404: Waiting for 250 worker threads to exit.

[Fri Oct 20 11:11:47 2006] [notice] Child 1404: All worker threads have exited.

[Fri Oct 20 11:11:47 2006] [notice] Child 1404: Child process is exiting

[Fri Oct 20 11:11:59 2006] [notice] Parent: Received restart signal -- Restarting the server.

[Fri Oct 20 11:11:59 2006] [notice] Child 3036: Exit event signaled. Child process is ending.

[Fri Oct 20 11:11:59 2006] [notice] Apache/2.0.58 (Win32) configured -- resuming normal operations

[Fri Oct 20 11:11:59 2006] [notice] Server built: Apr 29 2006 17:47:10

[Fri Oct 20 11:11:59 2006] [notice] Parent: Created child process 1724

[Fri Oct 20 11:12:00 2006] [notice] Child 1724: Child process is running

[Fri Oct 20 11:12:00 2006] [notice] Child 3036: Released the start mutex

[Fri Oct 20 11:12:00 2006] [notice] Child 1724: Acquired the start mutex.

[Fri Oct 20 11:12:00 2006] [notice] Child 1724: Starting 250 worker threads.

[Fri Oct 20 11:12:01 2006] [notice] Child 3036: Waiting for 250 worker threads to exit.

[Fri Oct 20 11:12:01 2006] [notice] Child 3036: All worker threads have exited.

[Fri Oct 20 11:12:01 2006] [notice] Child 3036: Child process is exiting

[Fri Oct 20 11:12:08 2006] [notice] Parent: Received shutdown signal -- Shutting down the server.

[Fri Oct 20 11:12:08 2006] [notice] Child 1724: Exit event signaled. Child process is ending.

[Fri Oct 20 11:12:09 2006] [notice] Child 1724: Released the start mutex

[Fri Oct 20 11:12:10 2006] [notice] Child 1724: Waiting for 250 worker threads to exit.

[Fri Oct 20 11:12:10 2006] [notice] Child 1724: All worker threads have exited.

[Fri Oct 20 11:12:10 2006] [notice] Child 1724: Child process is exiting

[Fri Oct 20 11:12:10 2006] [notice] Parent: Child process exited successfully.

[Fri Oct 20 11:12:27 2006] [notice] Apache/2.0.58 (Win32) configured -- resuming normal operations

[Fri Oct 20 11:12:27 2006] [notice] Server built: Apr 29 2006 17:47:10

[Fri Oct 20 11:12:27 2006] [notice] Parent: Created child process 3972

[Fri Oct 20 11:12:27 2006] [notice] Child 3972: Child process is running

[Fri Oct 20 11:12:27 2006] [notice] Child 3972: Acquired the start mutex.

[Fri Oct 20 11:12:27 2006] [notice] Child 3972: Starting 250 worker threads.

Share this post


Link to post
Share on other sites
[Thu Oct 19 23:42:21 2006] [error] [client 127.0.0.1] File does not exist: C:/Apache/Apache2/htdocs/hora.py

Esta linha indica que você tentou executar hora.py na raiz do site. Você deve executá-lo no diretório cgi-bin, onde devem ser salvos os programas cgi, a não ser que o Apache esteja configurado de outra forma.

http://localhost/cgi-bin/hora.py

Share this post


Link to post
Share on other sites
Guest Luckxander

verifiquei a existência do arquivo hora.py dentro do diretório C:\Apache\Apache2\cgi-bin,

ao abrir o arquivo no bloco de notas, aparece desse jeito:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32

Type "copyright", "credits" or "license()" for more information.

****************************************************************

Personal firewall software may warn about the connection IDLE

makes to its subprocess using this computer's internal loopback

interface. This connection is not visible on any external

interface and no data is sent to or received from the Internet.

****************************************************************

IDLE 1.2

>>> #!c:/python25/python.exe

# hora.py - CGI que exibe a hora local do servidor

from time import time, localtime

print 'Content-type: text/html'

print

h, m, s = localtime(time())[3:6]

print '<HTML><BODY>'

print '<H1>Hora: %02d:%02d:%02d</H1>' % (h, m, s)

print '<P>* de acordo com o relógio interno deste servidor</P>'

print '</BODY></HTML>'

então executei:

http://localhost/cgi-bin/hora.py

e o browser exibiu:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

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

Apache/2.0.58 (Win32) Server at localhost Port 80

Observação: Configurei o Apache como localdomain e localhost, conforme recomendado.

Share this post


Link to post
Share on other sites
Guest Luckxander

Optei por instalar outra versão do python e agora funcionou.

Obrigado pela atenção...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this