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 3的bytes/str之別Python
- t01_json_strJSON
- python str與bytes之間的轉換Python
- TypeError: only integer scalar arrays can be converted to a scalar indexErrorIndex
- rman: can't open target
- Effective Python(3)- 瞭解 bytes 與 str 的區別Python
- mail can't send title on SolarisAI
- Pycharm:設定完Anaconda後報錯TypeError: an integer is required (got type bytes)PyCharmErrorUIGo
- python用pyinstaller生成exe時報錯 TypeError: an integer is required (got type bytes)PythonErrorUIGo
- datastage7.5 can't view data?ASTView
- Mongoose can't update timestampGo
- [ERROR] Can't open the mysql.plugin tableErrorMySqlPlugin
- mysql遇到Variable can’t be set to the value of ‘NULL’MySqlNull
- Oracle dbconsole can't startOracle
- mysql can't start dues to the disk space is fullMySql
- redis : Can't save in background: fork: Cannot allocate memoryRedis
- Supervisor 解決 can't find command *
- Can't load IA 32-bit .dll on a
- eslint --fix 報錯 can't not find modulesEsLint
- mysql [ERROR] Can't create IP socket: Permission deniedMySqlError
- 解決can't find -lGL的問題
- MongoDB報錯:"assertion" : "can't map file memory"MongoDB
- RMAN的"rman: can't open target"錯誤
- You can‘t specify target table ‘Person‘ for update in FROM clause
- WIN配置git 配置後失敗 can't be establishedGit
- cordova 解決can’t not find moudle " plugman platform ios"PlatformiOS
- 異常: 'ascii' codec can't encode charactersASCII
- [jenkins]Can’t connect to window server – not enough permissionsJenkinsServer
- can't create PID file問題處理
- TypeError: Tensor objects are only iterable when eager execution is enabled. To iterate over this tErrorObject
- Troubleshooting when srvctl can't start RAC instance, but sqlplus can start it [ID 844272.1]SQL
- multiprocessing pool AttributeError: Can't get attribute 'func'Error
- mysql中You can’t specify target table for update in FROM clMySql
- mha_replication_check Can't exec "mysqlbinlog": No such file or directoryMySql
- Mysql報錯Fatal error:Can't open and lock privilege tablesMySqlError
- The scripts outputs "Can't locate Net/SNMP.pm in @INC.....
- MySQL不能啟動 Can't start server : Bind on unix sockeMySqlServer