Python Requests - Dynamically Pass HTTP Verb

前端 未结 2 1660
日久生厌
日久生厌 2021-02-19 02:33

Is there a way to pass an HTTP verb (PATCH/POST) to a function and dynamically use that verb for Python requests?

For example, I want this function to take a \'verb\' va

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-19 02:55

    Just use the request() method. First argument is the HTTP verb that you want to use. get(), post(), etc. are just aliases to request('GET'), request('POST'): https://requests.readthedocs.io/en/master/api/#requests.request

    verb = 'POST'
    response = requests.request(verb, headers=self.auth,
         url=self.API + '/zones/' + str(zID) + '/dns_records',
         data={"type":record[0], "name":record[1], "content":record[2]}
    )
    

提交回复
热议问题