question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: can't concat bytes to str (Python 3.5, thrift-sasl with pure-sasl)

See original GitHub issue

Due to issue #237 , I removed sasl 0.2.1 and replaced it with pure-sasl 0.3.0 based on this commit by @nonsleepr : https://github.com/cloudera/impyla/commit/5e386d6495b580ae88efd81dd0f8927af5157bb8

but then I got below error:

>>> conn = connect(host='<host>', port=21050, database='<db>', auth_mechanism='PLAIN', user='<user>', password='<pass>')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/python/miniconda3/lib/python3.5/site-packages/impala/dbapi.py", line 147, in connect
    auth_mechanism=auth_mechanism)
  File "/tmp/python/miniconda3/lib/python3.5/site-packages/impala/hiveserver2.py", line 758, in connect
    transport.open()
  File "/tmp/python/miniconda3/lib/python3.5/site-packages/thrift_sasl-0.2.1-py3.5.egg/thrift_sasl/__init__.py", line 75, in open
  File "/tmp/python/miniconda3/lib/python3.5/site-packages/thrift_sasl-0.2.1-py3.5.egg/thrift_sasl/__init__.py", line 94, in _send_message
TypeError: can't concat bytes to str

I am using:

  • CDH 5.8 / 5.9
  • Anaconda Python 3.5
  • impyla 0.14.0
  • bitarray 0.8.1
  • thriftpy 0.3.9
  • six 1.10.0
  • thrift-sasl 0.2.1 (installed via pip with ‘–no-deps’ option)
  • pure-sasl 0.3.0

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
ha62791commented, Jan 27, 2017

By changing line 94 in thrift_sasl/__init__.py to

print('Type of header:' + str(type(header)))
print('Type of body:' + str(type(body)))
self._trans.write(header + body.encode())

The output shows that on the first time _send_message is called body is passed as str. The second time it is passed correctly as bytes

Type of header:<class 'bytes'>
Type of body:<class 'str'>
Type of header:<class 'bytes'>
Type of body:<class 'bytes'>

Here’s a fix for the problem After installing:

  • thrift-sasl 0.2.1 (installed via pip with ‘–no-deps’ option)
  • pure-sasl 0.3.0

Go to directory <site-packages path>\thrift_sasl Remove __pycache__ if exists Append below codes before line 94 self._trans.write(header + body) in __init__.py:

    if (type(body) is str):
      body = body.encode()
5reactions
fat8701commented, Sep 25, 2019
modify thrift_sasl\__init__.py
...
  def _send_message(self, status, body):
    header = struct.pack(">BI", status, len(body))
------
#add code
    if (type(body) is str):
      body = body.encode()
------
    self._trans.write(header + body)
    self._trans.flush()

it works for me

  • python3.7
  • thrift-sasl==0.4a1
  • thriftpy2==0.4.0
  • pure-sasl==0.6.1
  • impyla==0.15.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: can't concat str to bytes in Python
The Python "TypeError: can't concat str to bytes" occurs when we try to concatenate a bytes object and a string. To solve the...
Read more >
python - Can't concat bytes to str
subprocess.check_output() returns a bytestring. In Python 3, there's no implicit conversion between unicode ( str ) objects and bytes objects.
Read more >
Making Impala connection from Python on Windows ...
Install Microsoft Visual C++ Compiler for Python 2.7 (see ... impyla thrift_sasl pure-sasl ... TypeError: can't concat bytes to str
Read more >
python3.5连接hive(impala)_我心依依旧的博客
环境python 3.5win 7一、按照以下顺序安装所需的包及版本:pip ... pip install pure-sasl ... 报如下错误TypeError: can't concat str to bytes.
Read more >
TypeError: can't concat bytes to str (Python 3.5, thrift-sasl with pure ...
Due to issue #237 ,I removed sasl 0.2.1 and replaced it with pure-sasl 0.3.0based on this commit by @nonsleepr : https.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found