Running twisted http server - "Method Not Allowed" error

Q

qwejohn

Hello,

I had posted this question in the twisted mailing list but did not
got a solution ; I hope that the python Gurus of this forum can help me
a bit.

I am trying the exmaple in the python docs -
http://twistedmatrix.com/users/warner/doc-latest/web/howto/using-twistedweb.xhtml

Configuring and Using the Twisted.Web Server - Twisted Web Development.

it says there:

"You can also create a Site instance by hand, passing it a Resource
object which will serve as the root of the site:

from twisted.web import server, resource
from twisted.internet import reactor

class Simple(resource.Resource):
isLeaf = True
def render_GET(self, request):
return "<html>Hello, world!</html>"

site = server.Site(Simple())
reactor.listenTCP(8080, site)
reactor.run() "

So I prepared a script named myhttp exactly like this and ran ./myhttp

I had made sure with netstat that indeed port 8080 was free before
running the script and after
running the script it was in a listening state.

But when pointing the Mozilla browser to http://localhost:8080 (or
http://127.0.0.1:8080)
I got the following error:

"Method Not Allowed
Your browser approached me (at /) with the method "GET". I only allow
the method here."

I had also made sure that there in no problem with iptables and that
the iptable service is down.

I had also tried:


telnet localhost 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0

And I got this as a response:

HTTP/1.0 405 Method Not Allowed
Date: Tue, 31 May 2005 13:45:29 GMT
Content-length: 242
Content-type: text/html
Allow: ()
Server: TwistedWeb/2.0.0

<html>
<head><title>405 - Method Not Allowed</title></head>
<body><h1>Method Not Allowed</h1>
<p>Your browser approached me (at /) with the method "GET".
I only
allow the method here.</p>
</body></html>

Connection closed by foreign host.


Tracing this error shows that this it stems from twisted/web/server.py.
I also tried it on a second machine with the latest stable releases
(TwistedWeb-0.5.0, Twisted-2.0.1 , Python-2.4.1, and
ZopeInterface-3.0.1)
and I got the same error.

I am trying it on RedHat 9 Linux (x386 based).

Any idea ?

Am I missing something?


Any help will be appreciated.

Regards,
John
 
R

Richard Townsend

from twisted.web import server, resource
from twisted.internet import reactor

class Simple(resource.Resource):
isLeaf = True
def render_GET(self, request):
return "<html>Hello, world!</html>"

site = server.Site(Simple())
reactor.listenTCP(8080, site)
reactor.run() "

Try adding the line:

allowedMethods = ('GET',)

after the line

isLeaf = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top