1

I'm working with Django and Piston and I created the following Handler:

from piston.handler import BaseHandler
import datetime
import json

class NotificationHandler( BaseHandler ):
  allowed_methods = ('POST',)

  def create( self, request, token ):
    return json.dumps( datetime.datetime.now() )

When making a request to this handler I'm getting an html page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>something</title>
  <META name="description" content="something"><META name="keywords" content="something">
</head>
<frameset rows="100%,*" border="0">
  <frame src="http://something.com/pay/notify/345345/" frameborder="0" />
  <frame frameborder="0" noresize />
</frameset>
<!-- pageok -->
<!-- 03 -->
<!-- -->
</html>

It looks like it's wripping the call into a frameset. However I would expect to get something like:

"2012-01-11 00:17:24"

I'm using apache with mod_wsgi. When running the project locally from the server provided by the PyCharm IDE I get the expected json value.

Not sure why I'm getting different results since I'm using the same script to make the request (with the same headers).

What would make Piston return an HTML page instead of a raw json string? May it be a header?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
JPs
  • 11
  • 2
  • 2
    It doesn't look like it's wrapping the call at all- if it were, your datetime would still be somewhere in that HTML. Rather, it looks like your create function is never called (you can confirm that by, say, raising an Exception in the create method). Are you certain the request reaches the handler? – David Robinson Jan 11 '12 at 05:47
  • I just realize that if I write the service address as http:///notify it works just fine, however if I put http:///notify it returns all the html code and not going into the handler. I also tested it as a GET method and if I put the same urls in the browser I get the same result when looking at the webpage source code and if I click on the link in frame I get what I would expect (since that url is using the IP). It looks like domain masking is what is causing the problems. Any idea on how this could work? I'm using GoDaddy.com – JPs Jan 11 '12 at 23:34
  • I finally found that the problem has to do only with the domain forwarding. I was using url masking options which add the html wraper with frameset. If I remove this option I get the right response from a read (GET) handler. When using POST it's still removing the data I'm sendding and I'm getting a GET instead. Will have to look into that, however, thats not a python/piston problem. – JPs Jan 12 '12 at 04:21

2 Answers2

0

Check your Apache configuration and make sure that the function is called (raising an exception like proposed by David Robinson).

luc
  • 41,928
  • 25
  • 127
  • 172
0

Consider using the WSGI application wrapper described in:

http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Tracking_Request_and_Response

to capture both input and output for the request.

This will allow you to verify whether Django gets called, plus what is returned into mod_wsgi and so determine if issue is within Django of whether Apache caching or something else if causing issue after application returns response.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134