How to make HTTP DELETE method using urllib2?

前端 未结 5 1070
忘掉有多难
忘掉有多难 2020-12-05 03:49

Does urllib2 support DELETE or PUT method? If yes provide with any example please. I need to use piston API.

5条回答
  •  -上瘾入骨i
    2020-12-05 04:54

    Correction for Raj's answer:

    import urllib2
    class RequestWithMethod(urllib2.Request):
      def __init__(self, *args, **kwargs):
        self._method = kwargs.pop('method', None)
        urllib2.Request.__init__(self, *args, **kwargs)
    
      def get_method(self):
        return self._method if self._method else super(RequestWithMethod, self).get_method()
    

提交回复
热议问题