How to make HTTP DELETE method using urllib2?

前端 未结 5 1072
忘掉有多难
忘掉有多难 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:31

    Found following code from https://gist.github.com/kehr/0c282b14bfa35155deff34d3d27f8307 and it worked for me (Python 2.7.5):

    import urllib2
    
    request = urllib2.Request(uri, data=data)
    request.get_method = lambda: 'DELETE'
    response = urllib2.urlopen(request)
    

提交回复
热议问题