Tuesday, 15 June 2010

Make POST request using Python -


I'm trying to make a post request, but getting this error:

  Tracebacks (Most Recent Call End): File "demo.py", line 7, in & lt; Module & gt; R = requests.post (url, data = payload, header = header) in the file "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 87, in return request ( 'Post', url, data = data, ** kwargs) file "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, request return session .request (method = Method, url = url, ** kwargs) file "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 266, prep = req.prepare () file in the request "/ usr / Local /lib/python2.7/dist-packages/requests/models.py ", line 215, p. The file "/usr/local/lib/python2.7/dist- package / request / model_jap", line 338, ready_edition body = self._encode_params (data) file "/ usr /" in preparing prepay_body (self-data, self file) Local / lib / python2.7 / dist-packages / requests / models.py ", in line 74,   

This is my program:

  import Requests url = 'http: // import' url = '_encode_params' vs. to_key_val_list (data) for 'http': value error:: //www.n-gal.com/index.php? Route = openstock / openstock / option 'status' pa yload = {'var: 1 9 45, product_id: 1126'} header = {'content-type': 'application / x-www-form-urlencoded'} r = request .post (url, data = payload, header = header)   

I have tried the same post request through the advanced client using the following data:

P> URL: http://www.n-gal.com/ Index.php? Route = openstock / openstock / optionStatus payload: var = 1 9 45 and product_id = 1126 content type: application / x-www-form-urlencoded

And it is working fine, please anyone can help me ...

Try it:

  import request url = 'http://www.n-gal.com/index.php?route=openstock/openstock/optionStatus' payload =' var = 1 9 45 and product_id = 1126 'header = {' content-type ':' application / x-www-form-urlencoded '} r = requests.post (URL, data = payload, header = header) printed by R. Jason ( )    

No comments:

Post a Comment