How do I make a PATCH request in Python?

前端 未结 4 1320
Happy的楠姐
Happy的楠姐 2021-01-04 00:27

Is there a way to make a request using the PATCH HTTP method in Python?

I tried using httplib, but it doesn\'t accept PATCH as method param.

4条回答
  •  一向
    一向 (楼主)
    2021-01-04 00:57

    Seems to work in 2.7.1 as well.

    >>> import urllib2
    >>> request = urllib2.Request('http://google.com')
    >>> request.get_method = lambda: 'PATCH'
    >>> resp = urllib2.urlopen(request)
    Traceback (most recent call last):
     ...
    urllib2.HTTPError: HTTP Error 405: Method Not Allowed
    

提交回复
热议问题