http - Making put/post from Tornado doesent work -


i trying make put method (or post) dropbox api, doesent work, get instead?

import tornado.ioloop import tornado.web tornado.httputil import httpheaders tornado.httpclient import httpclient, httprequest  url = "https://api-content.dropbox.com/1/files_put/sandbox/world.txt"  class mainhandler(tornado.web.requesthandler):     def post(self):         headers = httpheaders({'authorization': 'bearer token_for_dropbox'})         httpclient().fetch(         httprequest(url, 'put', body="hello there", headers=headers))  application = tornado.web.application([     (r"/", mainhandler), ])  if __name__ == "__main__":     application.listen(8888) tornado.ioloop.ioloop.current().start() 

update: using get makes error: httperror: http 400: bad request

here new code:

import tornado.ioloop import tornado.web tornado.httpclient import httpclient, httprequest  url = "https://api-content.dropbox.com/1/files_put/sandbox/wor.txt"  class mainhandler(tornado.web.requesthandler):     def get(self):         self.set_header('authorization', 'bearer dropbox_token')         self.set_header('content-type', 'text/plain')                 httpclient().fetch(         httprequest(url, 'put', body="hello there"))  application = tornado.web.application([     (r"/", mainhandler), ])  if __name__ == "__main__":     application.listen(8888)     tornado.ioloop.ioloop.current().start() 

but error:

traceback (most recent call last): file "c:\python27\lib\site-packages\tornado\web.py", line 1415, in _execute result = yield result file "c:\python27\lib\site-packages\tornado\gen.py", line 870, in run value = future.result() file "c:\python27\lib\site-packages\tornado\concurrent.py", line 215, in result raise_exc_info(self._exc_info) file "c:\python27\lib\site-packages\tornado\gen.py", line 230, in wrapper yielded = next(result) file "c:\users\abdelouahab\desktop\ttttt.py", line 14, in httprequest(url, 'put', body="hello there")) file "c:\python27\lib\site-packages\tornado\httpclient.py", line 102, in fetch self._async_client.fetch, request, **kwargs)) file "c:\python27\lib\site-packages\tornado\ioloop.py", line 445, in run_sync return future_cell[0].result() file "c:\python27\lib\site-packages\tornado\concurrent.py", line 215, in result raise_exc_info(self._exc_info) file "<string>", line 3, in raise_exc_info httperror: http 401: unauthorized error:tornado.access:500 / (::1) 806.00ms

i tried using http request builder extension mozilla, , worked, guess problem how on tornado?

sorry, seems missed content-type

import tornado.ioloop import tornado.web tornado.httputil import httpheaders tornado.httpclient import httpclient, httprequest tornado.gen import coroutine  url = "https://api-content.dropbox.com/1/files_put/sandbox/wor.txt"  class mainhandler(tornado.web.requesthandler):     @coroutine         def get(self):         headers = httpheaders({'authorization': 'bearer dropbox_token', 'content-type':'text/plain'})         httpclient().fetch(         httprequest(url, 'put', body="hello there", headers=headers))   application = tornado.web.application([     (r"/", mainhandler), ])  if __name__ == "__main__":     application.listen(8888)     tornado.ioloop.ioloop.current().start() 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -