zoukankan      html  css  js  c++  java
  • Python3.x:报错POST data should be bytes, an iterable of bytes

    Python3.x:报错POST data should be bytes, an iterable of bytes

    问题:

    python3.x:报错

    POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

    原因:

    # 组装GET方法的请求
    request = urllib2.Request(url, data, headers)  

    其中的data需要转为utf-8

    解决方案:

    # 组装GET方法的请求
    #将代码request = urllib2.Request(url, data, headers)  更改为
    request = urllib.request.Request(url, data=urllib.parse.urlencode(data).encode(encoding='UTF8'), headers=headers) 
  • 相关阅读:
    装饰器(一)
    函数内置方法
    递归
    函数(三)
    python常用模块
    python模块与包
    python内置函数
    python函数
    python文件处理
    函数编程
  • 原文地址:https://www.cnblogs.com/lizm166/p/8207121.html
Copyright © 2011-2022 走看看