【问题标题】:how to parametrize url in put requests using python如何使用python参数化放置请求中的url
【发布时间】:2018-02-28 11:23:20
【问题描述】:

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

【问题讨论】:

  • 控制器好像不支持“PUT”方法,试试requests.get(url=URL,data=data, verify=False)
  • 这与您正在格式化字符串这一事实无关(尝试requests.put(url="https://192.168.72.31/UDW/Command?entry=eprint.register",data=data, verify=False)您确定可以将 PUT 与该 url 一起使用吗?

标签: python python-2.7 rest python-requests


【解决方案1】:

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

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"
        }

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

    • 是的。这个假设已经存在于 cmets 中。您能否添加有关此问题的更多信息?
    • 抱歉没有花时间阅读 cmets。如果@Sum 想分享他使用的后端代码和框架,我可以添加更多信息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    相关资源
    最近更新 更多