ralhei / pyRserve

A python client for Rserve (network layer to remote R server)
Other
48 stars 13 forks source link

TypeError: a bytes-like object is required, not 'str' #17

Closed pidupuis closed 7 years ago

pidupuis commented 7 years ago
Python 3.5.1 (default, Nov 10 2016, 10:33:53) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyRserve
>>> conn = pyRserve.connect()
>>> print(conn)
<Handle to Rserve on localhost:6311>
>>> conn.eval('2+3')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/toto/.pyenv/versions/tata/lib/python3.5/site-packages/pyRserve/rconn.py", line 78, in decoCheckIfClosed
    return func(self, *args, **kw)
  File "/home/toto/.pyenv/versions/tata/lib/python3.5/site-packages/pyRserve/rconn.py", line 157, in eval
    self._reval(aString, void)
  File "/home/toto/.pyenv/versions/tata/lib/python3.5/site-packages/pyRserve/rconn.py", line 144, in _reval
    rEval(aString, fp=self.sock, void=void)
  File "/home/toto/.pyenv/versions/tata/lib/python3.5/site-packages/pyRserve/rserializer.py", line 404, in rEval
    return s.finalize()
  File "/home/toto/.pyenv/versions/tata/lib/python3.5/site-packages/pyRserve/rserializer.py", line 103, in finalize
    self._buffer.write('\x00\x00\x00\x00')  # data offset, zero by default
TypeError: a bytes-like object is required, not 'str'
>>> quit()

It works if I comment the following line: self._buffer.write('\x00\x00\x00\x00') # data offset, zero by default

Any idea?

ralhei commented 7 years ago

This issue is now fixed, please get the latest version from github (it is not yet published on pypi). Thanks for your report.

Shih-Wei-Hsu commented 6 years ago

import pyRserve conn = pyRserve.connect(host="172.16.82.159",port=6311) conn.eval("library(Rserve)") conn.eval("Rserve()") conn.eval("library(RJDBC)") conn.eval("library('rjson')") conn.eval("library('jsonlite')") conn.eval("library('lubridate')") conn.eval("drv<-JDBC('org.apache.hive.jdbc.HiveDriver',list.files('/opt/cloudera/parcels/CDH/jars',pattern='jar$',full.names=T,recursive=TRUE))") Traceback (most recent call last): File "I:\workspace\python\pyRserveTest.py", line 18, in <module> conn.eval("drv<-JDBC('org.apache.hive.jdbc.HiveDriver',list.files('/opt/cloudera/parcels/CDH/jars',pattern='jar$',full.names=T,recursive=TRUE))") File "G:\IT-learn\python35\lib\site-packages\pyRserve\rconn.py", line 78, in decoCheckIfClosed return func(self, *args, **kw) File "G:\IT-learn\python35\lib\site-packages\pyRserve\rconn.py", line 170, in eval message = rparse(src, atomicArray=atomicArray) File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 640, in rparse return rparser.parse() File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 438, in parse message = self._parse() File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 466, in _parse lexeme = self._parseExpr() File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 479, in _parseExpr lexeme.setAttr(self._parseExpr()) File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 482, in _parseExpr self[None])(self, lexeme) File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 608, in xt_list_tag value, tag = self._parseExpr().data, self._parseExpr().data File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 482, in _parseExpr self[None])(self, lexeme) File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 540, in xt_array data = self._nextExprData(lexeme) File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 488, in _nextExprData data = self.lexer.nextExprData(lexeme) File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 288, in nextExprData return self.lexerMap[lexeme.rTypeCode](self, lexeme) File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 351, in xt_array_str strList = [stringEncode(byteString) for byteString in bytesStrList] File "G:\IT-learn\python35\lib\site-packages\pyRserve\rparser.py", line 351, in <listcomp> strList = [stringEncode(byteString) for byteString in bytesStrList] File "G:\IT-learn\python35\lib\site-packages\pyRserve\misc.py", line 52, in stringEncode return byteData.decode(encoding=encoding) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Hello , i encountered such a problem when it executed in win64, please give me an idea .Thank you very much.