0

I have implemented API with django piston in which its take data from sms/mms . For MMS case i have to post XML data with image and others . Here is my code snippet on handlers.py

def create(self, request,*args,**kwagrs):
    try:
      file_type = None                
      raw_data = request.raw_post_data                
      data = serializers.deserialize("xml", raw_data)     
      try:                  
        parser = Parse(data.stream.getvalue())
        message = parser.get_message()                
        action_id = parser.get_action_id()                    
      except Exception,e:              
        return HttpResponse(Response({'sender':parser.get_sender(),'error_description':str(e)}).get_error_response(), mimetype='text/xml')                     

      if action_id in ['o','m','vt','vh','yritys']:
         return self.post_message(request,parser)
      elif action_id == 'poista' or action_id == 'lopeta':
         return self.expired_message(request,parser)
      elif action_id == 'tiedot':
         return self.get_contact_info(request,parser)            
  except Exception,e:
      ad_id = None
      return HttpResponse(Response({'sender':parser.get_sender(),'error_description':str(e)}).get_error_response(), mimetype='text/xml')

when I am posting xml data with CURL its working , but when i use Firefox, httprequester its throwing me "BAD REQUEST"

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
paul
  • 51
  • 2
  • 11
  • Inspect the 400 that comes back when you POST (use Firebug, or Chrome/Safari web inspector). It may be that you're sending inappropriate arguments - piston should give you some kind of deedback – Steve Jalim Jan 25 '12 at 16:24
  • well its api and i am using httpRequester to post this , so how can i check this with Firebug? Please suggest. – paul Jan 26 '12 at 08:53

2 Answers2

1

Check this: I get a 400 Bad Request error while using django-piston

Create middleware as:

class ContentTypeMiddleware(object):

    def process_request(self, request):
        if 'charset=UTF-8' in request.META['CONTENT_TYPE']:
            request.META['CONTENT_TYPE'] = request.META['CONTENT_TYPE'].replace('; charset=UTF-8','')
        return None

Add it in settings:

MIDDLEWARE_CLASSES = ( 'app.middleware.ContentTypeMiddleware', )

Community
  • 1
  • 1
anils
  • 1,782
  • 6
  • 19
  • 29
0

Try hurl.it for API testing. Check your post data. Set your header info if required.

Tauquir
  • 6,613
  • 7
  • 37
  • 48