Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不带编码的python 3字符串参数_Python_String - Fatal编程技术网

不带编码的python 3字符串参数

不带编码的python 3字符串参数,python,string,Python,String,这段代码适用于Python2.7,但在Python3.4上,我得到了“字符串参数不带编码”错误 bytes()类构造函数现在希望将编码作为第二个参数。例如: bytes("mystring", "ascii") 我想你需要这样的东西: headers = {'Authorization' : 'Basic ' + base64.b64encode(bytes('Someuser:Somepassword','ascii')).decode('ascii')} 如果这是硬编码文字,则可能重复使

这段代码适用于Python2.7,但在Python3.4上,我得到了“字符串参数不带编码”错误

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

bytes("mystring", "ascii")

我想你需要这样的东西:

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

如果这是硬编码文字,则可能重复使用
b'Someuser:Somepassword'
headers = {'Authorization' : 'Basic ' + base64.b64encode(bytes('Someuser:Somepassword','ascii')).decode('ascii')}