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

问题描述 投票:0回答:2

我正在尝试使用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错误(方法不允许响应状态代码)。

python python-2.7 rest python-requests
2个回答
0
投票

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

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
投票

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

在烧瓶:@app.route('/your_route', methods=['PUT'])

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

© www.soinside.com 2019 - 2024. All rights reserved.