python - HTTPError when sending POST with urllib2 with params -


I am trying to send a post request using some of the following criteria using this code: < pre> def _ws_save_manifest (self): url = 'http: // localhost: 8000 / extras / save_manifest /' xml_string = 'example' params = {'xml_string': xml_string} data = urllib.urlencode (params) requests = urllib2.Request (url, data) request.add_header ('user-agent', 'mozilla / 5.0 (windows; u; windows nt 5.1; d; rv .: 1.9.1.5) gicco / 20091102 firefox / 3.5 5 ') request.add_header (' Content Result ['OK']: 'Return', 'Application / X- www- Form- Url encode ') response = urllib2.urlopen (requested) #response = urllib2.urlopen (url) result = json.load (response) if the result [' ok ']: return true return false

Although I get the following error:

  file "/usr/lib/python2.7/urllib2.py", line 528, HTTPError in Http_error_default (req.get_full_url (), code, msg , hdrs, fp) urllib2.HTTP Error: HTTP Error 403: FORBIDDEN   

In using GET, I have no problem, but by sending the header

by the way The only: the request is using the Django and that RL (which works perfectly with GET):

  url (r ^ ^ extras / Save_manifest / $ ',' extras.views.save_manifest '),  < The problem is, that the post request cross-site request forged with the Django is protected forged. See for more information.   

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -