How to make HTTP DELETE method using urllib2?

前端 未结 5 1076
忘掉有多难
忘掉有多难 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条回答
  •  鱼传尺愫
    2020-12-05 04:30

    You can subclass the urllib2.Request object and override the method when you instantiate the class.

    import urllib2
    
    class RequestWithMethod(urllib2.Request):
      def __init__(self, method, *args, **kwargs):
        self._method = method
        urllib2.Request.__init__(*args, **kwargs)
    
      def get_method(self):
        return self._method
    

    Courtesy of Benjamin Smedberg

提交回复
热议问题