【问题标题】:python3 urllib, make put request with no datapython3 urllib,发出没有数据的请求
【发布时间】:2018-11-04 21:05:06
【问题描述】:

你好,我有一个 C# 服务,它接受一个没有数据的 put 请求,它只是触发一个算法。

我正在使用 urllib 向此服务发出请求,但是收到 411 错误。这是因为我没有提供数据参数。

req = urllib.request.Request(url, headers=headers, method='PUT')

try:
  response = urllib.request.urlopen(req)

HTTP错误:411

如果我试试这个:

req = urllib.request.Request(url, headers=headers,DATA="" method='PUT')

try:
  response = urllib.request.urlopen(req)

TypeError: POST 数据应该是字节或可迭代的字节。它不能是 str 类型。

有人可以帮助我,请不要只说“huuu durr use requests”我不能使用进口。谢谢

【问题讨论】:

    标签: python-3.x http python-requests urllib


    【解决方案1】:

    好的,我通过以下方式解决了这个问题:

    req = urllib.request.Request(url, headers=headers,DATA=b'' method='PUT')
    
    try:
      response = urllib.request.urlopen(req)
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-30
      • 2021-05-14
      • 2014-10-18
      • 1970-01-01
      • 2016-07-28
      • 2023-03-10
      相关资源
      最近更新 更多