Ir para conteúdo
Fórum Script Brasil
  • 0

Dúvida


Guest Luckxander

Pergunta

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>'

Link para o comentário
Compartilhar em outros sites

7 respostass a esta questão

Posts Recomendados

  • 0

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?

Link para o comentário
Compartilhar em outros sites

  • 0
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.

Link para o comentário
Compartilhar em outros sites

  • 0
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)

Link para o comentário
Compartilhar em outros sites

  • 0
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.

Link para o comentário
Compartilhar em outros sites

  • 0
[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

Link para o comentário
Compartilhar em outros sites

  • 0
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, lu@pilares.net 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.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...