How do I make a PATCH request in Python?

前端 未结 4 1307
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:59

    I tried this in Python 3, and it seemed to work (but I don't have a server handy that supports the PATCH request type):

    >>> import http.client
    >>> c = http.client.HTTPConnection("www.google.com")
    >>> r = c.request("PATCH", "/index.html")
    >>> print(r.status, r.reason)
    405 Method Not Allowed
    

    I'm assuming that the HTTP 405 is coming from the server and that it is "not allowed".

    By the way, thanks for showing me the cool PATCH method in HTTP.

提交回复
热议问题