Haha, resolved now. Previously my setup wasn't sensitive to a missing trailing slash on my PUT and POSTs, but now it is. I don't know why, but at least it's solvable.<div><br></div><div>Thanks for the help</div>
<div>Brad<br><br><div class="gmail_quote">On 11 February 2010 08:59, Brad Milne <span dir="ltr"><<a href="mailto:brad.milne@devx.runthered.com">brad.milne@devx.runthered.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
End of trace is:<div><div> File "C:\Python26\lib\site-packages\twisted\web\resource.py", line 189, in render</div><div> raise UnsupportedMethod(getattr(self, 'allowedMethods', ()))</div><div>twisted.web.server.UnsupportedMethod: ()</div>
<div><div></div><div class="h5">
<br><div class="gmail_quote">On 11 February 2010 08:20, Brad Milne <span dir="ltr"><<a href="mailto:brad.milne@devx.runthered.com" target="_blank">brad.milne@devx.runthered.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks. I had actually already found your page and you're right, it does seem to be the best resource out there. Since your email I've had a second look at it, as initially I wasn't sure how to use the example to return a web resource (handler with render_GET etc) in place of the file you returned. Turns out it wasn't actually too bad, and looks something like:<br>
<br>{code}<br><pre><div>from zope.interface import implements<br><br></div>from twisted.cred.portal import IRealm, Portal<br>from twisted.cred.checkers import FilePasswordDB<br>from twisted.web.static import File<br>
from twisted.web.resource import IResource<br>
from twisted.web.guard import HTTPAuthSessionWrapper, DigestCredentialFactory<br><br>def secureServer():<br> class PublicHTMLRealm(object):<br> implements(IRealm)<br><br> def requestAvatar(self, avatarId, mind, *interfaces):<br>
if IResource in interfaces:<br> return (IResource, WebResource(), lambda: None)<br> raise NotImplementedError()<br><br> portal = Portal(PublicHTMLRealm(), [FilePasswordDB('httpd.password')])<br>
<br> credentialFactory = BasicCredentialFactory("MyRealm")<br> rsrc = HTTPAuthSessionWrapper(portal, [credentialFactory])<br><br> return rsrc<br><br>class WebResource(resource.Resource):<br> def __init__():<br>
....<br><br> def getChild(self, path, request):<br> if path == self.expected:<br> return ValidHandler()<br> else:<br> return InvalidUrlHandler()<br><br># Create server<br>my_server = secureServer(...)<br>
site = server.Site(my_server)<br></pre>{code}<br><br>This has worked great so far where ValidHandler contains a render_GET, but when calling a POST or PUT on handler that has render_POST or render_PUT using this technique returns a message which I think is Method Not Allowed (on the train right now, so don't have in front of me, sorry). Is there a better way to form the above to prevent this?<br>
<br>Thanks again<br>Brad<br><br><div class="gmail_quote">On 9 February 2010 10:02, <span dir="ltr"><<a href="mailto:exarkun@twistedmatrix.com" target="_blank">exarkun@twistedmatrix.com</a>></span> wrote:<br>...<div>
<br><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
It's definitely true that there isn't a lot of documentation for Guard. I've written up something, though (which hopefully will soon be included in Twisted itself, to make it easier to find), which I think will get you up to speed on using Guard pretty quickly:<br>
<br>
<a href="http://jcalderone.livejournal.com/53074.html" target="_blank">http://jcalderone.livejournal.com/53074.html</a><br>
<br>
The final example, which sets up an actual Twisted Web server protected by digest auth (basic is even easier), only takes 16 lines.<br>
<br>
If that's still not to your liking, then you can always fall back to the much more tedious, much less elegant, request.getUsername() and request.getPassword() approach. :) You'll have to rely on the API docs for that approach, though, as far as I know there are no prose-style introductions for it.<br>
</blockquote></div><div>... <br></div><div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
<br>
Jean-Paul<br>
<br>
<br>_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br></blockquote></div></div><br>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div>