【问题标题】:python 3 string argument without an encoding没有编码的python 3字符串参数
【发布时间】:2017-03-23 01:49:17
【问题描述】:

此代码适用于 Python 2.7,但在 Python 3.4 上出现“没有编码的字符串参数”错误

headers = {'Authorization' : 'Basic ' + base64.b64encode(bytes('Someuser:Somepassword')).encode('ascii')}

【问题讨论】:

标签: python string


【解决方案1】:

bytes() 类构造函数现在期望编码作为第二个参数。示例:

bytes("mystring", "ascii")

【讨论】:

    【解决方案2】:

    我猜你需要这样的东西:

    headers = {'Authorization' : 'Basic ' + base64.b64encode(bytes('Someuser:Somepassword','ascii')).decode('ascii')}
    

    【讨论】:

      猜你喜欢
      • 2015-09-18
      • 1970-01-01
      • 2016-10-02
      • 2019-01-28
      • 2018-10-16
      • 2020-04-22
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多