TypeError: can‘t concat str to bytes
這是python2和python3的一個差別,python2可以直接將位元組和字串拼接,python3不可以:
$ python2
Python 2.7.18 (default, Aug 4 2020, 11:16:42)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> b'\x00\x00\x80@\x00\x00\xa0@'+''
'\x00\x00\x80@\x00\x00\xa0@'
$ python3
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> b'\x00\x00\x80@\x00\x00\xa0@'+''
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't concat str to bytes
解決方法:要麼兩邊都轉成字串,要麼兩邊都轉成位元組
這裡提供兩邊都轉成位元組的方法:
>>> b'\x00\x00\x80@\x00\x00\xa0@'+b''
b'\x00\x00\x80@\x00\x00\xa0@'
其他:https://blog.csdn.net/yatere/article/details/6606316
相關文章
- Python報錯:TypeError: a bytes-like object is required, not ‘str‘PythonErrorObjectUI
- python str與bytes之間的轉換Python
- t01_json_strJSON
- Effective Python(3)- 瞭解 bytes 與 str 的區別Python
- TypeError: only integer scalar arrays can be converted to a scalar indexErrorIndex
- Can't open file: (errno: 24)
- Pycharm:設定完Anaconda後報錯TypeError: an integer is required (got type bytes)PyCharmErrorUIGo
- python用pyinstaller生成exe時報錯 TypeError: an integer is required (got type bytes)PythonErrorUIGo
- Supervisor 解決 can't find command *
- Mongoose can't update timestampGo
- eslint --fix 報錯 can't not find modulesEsLint
- mysql遇到Variable can’t be set to the value of ‘NULL’MySqlNull
- MySQL 2003 - Can’t connect to MySQL server on (10060)MySqlServer
- Can't load IA 32-bit .dll on a
- multiprocessing pool AttributeError: Can't get attribute 'func'Error
- Python——UnicodeEncodeError: 'ascii' codec can't encode/decode charactersPythonUnicodeErrorASCII
- redis : Can't save in background: fork: Cannot allocate memoryRedis
- FILESTREAM feature can't be enabled if you use cluster shared volumes
- WIN配置git 配置後失敗 can't be establishedGit
- Error:Can't connect to SOCKS proxy:Connection refused (Connection refused)Error
- Python報錯:UnicodeDecodeError: 'gbk' codec can't decode byte ...PythonUnicodeError
- Mysql:Variable 'XXXt' can't be set to the value of 'NULL'解決MySqlNull
- You can‘t specify target table ‘Person‘ for update in FROM clause
- TypeError: Tensor objects are only iterable when eager execution is enabled. To iterate over this tErrorObject
- 完美解決stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.ErrorPython
- Fatal error: can't check configuration file '/home/watt/proxy/dError
- 解決ERROR 1231 (42000): Variable 'time_zone' can'tError
- python cx_Oracle: UnicodeEncodeError: 'ascii' codec can't encode charactersPythonOracleUnicodeErrorASCII
- why this draw call can‘t be batched with the previous one for Unity2019.4+BATUnity
- MYSQL報1022錯誤:Can't write;duplicate key in table '.....'MySql
- mysql中You can’t specify target table for update in FROM clMySql
- FileZilla:425 Can't open data connection for transfer of解決辦法
- 問題解決zipimport.ZipImportError: can‘t decompress data; zlib not availablImportErrorAI
- [mac pip錯誤]Can't connect to HTTPS URL because the SSL module is not availableMacHTTPAI
- Can't debug c++ project because unable to static library start program *.libC++Project
- 小程式真機報錯errMsg: “hideLoading:fail:toast can‘t be found“ ?IDEAIAST
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- OSError: [E050] Can‘t find model ‘en_core_web_sm‘. It doesn‘t seem to be a shortcut link, a Python pErrorWebPython