如何使用python在put请求中参数化url

时间:2018-02-28 11:23:21

标签: python python-2.7 rest python-requests

我正在尝试使用python在put请求中发送参数化的url。 我的一个函数“getipaddress()”将设备IP地址返回为192.168.72.31

代码:

import requests
ips= getipaddress()
URL = "https://%s/UDW/Command?entry=eprint.register" % ips
r = requests.put(url=URL,data=data, verify=False)
print r.status_code

获取错误:405错误(方法不允许响应状态代码)。

2 个答案:

答案 0 :(得分:0)

根据@Ami Hollander和@DeepSpace的输入,我发现不支持put请求。尝试使用get请求,我能够得到响应

Code :
      ips = getipaddress()   # returns device ip:192.168.72.31
      url = "https://%s/UDW/Command?entry=eprint.register" % ips  
      requests.get(url=URL,verify=False)

Output :
        {
          "state": 200,
          "eprint_reg_state": "registering"
        }

答案 1 :(得分:-1)

我猜你的服务器不接受PUT请求

Flask中的

@app.route('/your_route', methods=['PUT'])

Django中的

:不支持PUT请求,您需要使用http://www.django-rest-framework.org/