TypeError: can't concat str to bytes?
See original GitHub issueI got this TypeError: can't concat str to bytes
idk why,i just trying simple code like this
import routeros_api as routers
connection = routers.RouterOsApiPool('IP', username='username', password='password')
api = connection.get_api()
api.get_binary_resource('/').call('ping', { 'address': '192.168.56.1', 'count': '4' }) #this ip i got from example
And full traceback:
Traceback (most recent call last):
File "mikro.py", line 5, in <module>
api.get_binary_resource('/').call('ping', { 'address': '192.168.56.1', 'count': '4' })
File "/home/sengkunibot/.local/lib/python3.7/site-packages/routeros_api/resource.py", line 39, in call
additional_queries=additional_queries).get()
File "/home/sengkunibot/.local/lib/python3.7/site-packages/routeros_api/resource.py", line 45, in call_async
additional_queries=additional_queries)
File "/home/sengkunibot/.local/lib/python3.7/site-packages/routeros_api/api_communicator/encoding_decorator.py", line 12, in call
path, command, arguments, queries, additional_queries)
File "/home/sengkunibot/.local/lib/python3.7/site-packages/routeros_api/api_communicator/async_decorator.py", line 6, in call
tag = self.inner.send(*args, **kwargs)
File "/home/sengkunibot/.local/lib/python3.7/site-packages/routeros_api/api_communicator/exception_decorator.py", line 11, in send
return self.inner.send(*args, **kwargs)
File "/home/sengkunibot/.local/lib/python3.7/site-packages/routeros_api/api_communicator/key_cleaner_decorator.py", line 11, in send
queries=encoded_queries, additional_queries=additional_queries)
File "/home/sengkunibot/.local/lib/python3.7/site-packages/routeros_api/api_communicator/base.py", line 19, in send
self.send_command(command)
File "/home/sengkunibot/.local/lib/python3.7/site-packages/routeros_api/api_communicator/base.py", line 37, in send_command
self.base.send_sentence(command.get_api_format())
File "/home/sengkunibot/.local/lib/python3.7/site-packages/routeros_api/sentence.py", line 59, in get_api_format
formated.append(b'=' + key + b'=' + value)
TypeError: can't concat str to bytes
My server:
- Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)
- Python3.7
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
python - Can't concat bytes to str - Stack Overflow
subprocess.check_output() returns a bytestring. In Python 3, there's no implicit conversion between unicode ( str ) objects and bytes objects.
Read more >TypeError : cant concat str to bytes ( Solved )
The main or root cause of this error is that you are concatenating the string type to the bytes type. Mainly when you...
Read more >can't concat str to bytes - When configuring vlans on switch : r ...
The (b"... means that you want to work with bytes. You need to convert the str(n) to bytes too. Try - tn.write(b"vlan "...
Read more >TypeError: can't concat str to bytes` #25 - GitHub
the reason is str and bytes can't combine in python3, but it can be in python2. so we need to change str to...
Read more >makecat.py fails under python 3: TypeError: can't concat bytes ...
This is wrong -- workingcatname.encode('ascii', 'xmlcharrefreplace') will create a bytes object, and this cannot be concatenated with the '_exclude.txt' string.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same issue. I modified sentence.py file from library. Added lines with **. Seems to fix this but I don’t know about any other side effects
Two parts to the answer:
Simple way to make it work is to change the fields to bytes, like this:
However, it does raise the question about whether under Python3 that we should be handling better.