0

I know there are other questions about it but I did not find an appropriate answer to my question.

So I get the following error : TypeError: a bytes-like object is required, not 'str'

Traceback (most recent call last):
  File "/Users/danvdb/anaconda/bin/mrec_predict", line 9, in <module>
    load_entry_point('mrec==0.3.1', 'console_scripts', 'mrec_predict')()
  File "/Users/danvdb/anaconda/lib/python3.5/site-packages/mrec-0.3.1-py3.5-macosx-10.5-x86_64.egg/mrec/examples/predict.py", line 227, in main
    description,metrics = process(view,opts,modelfile,trainfile,testfile,opts.item_features,opts.outdir,evaluator)
  File "/Users/danvdb/anaconda/lib/python3.5/site-packages/mrec-0.3.1-py3.5-macosx-10.5-x86_64.egg/mrec/examples/predict.py", line 63, in process
    processed = [r.get() for r in results]
  File "/Users/danvdb/anaconda/lib/python3.5/site-packages/mrec-0.3.1-py3.5-macosx-10.5-x86_64.egg/mrec/examples/predict.py", line 63, in <listcomp>
    processed = [r.get() for r in results]
  File "/Users/danvdb/anaconda/lib/python3.5/site-packages/ipyparallel/client/asyncresult.py", line 167, in get
    raise self.exception()
  File "/Users/danvdb/anaconda/lib/python3.5/site-packages/ipyparallel/client/asyncresult.py", line 226, in _resolve_result
    results = error.collect_exceptions(results, self._fname)
  File "/Users/danvdb/anaconda/lib/python3.5/site-packages/ipyparallel/error.py", line 233, in collect_exceptions
    raise e
  File "/Users/danvdb/anaconda/lib/python3.5/site-packages/ipyparallel/error.py", line 231, in collect_exceptions
    raise CompositeError(msg, elist)
ipyparallel.error.CompositeError: one or more exceptions from call to method: run
[3:apply]: TypeError: a bytes-like object is required, not 'str'

And the code is the following (from predict.py) :

results = []
results.append(view.map_async(predict.run,tasks,retries=2))

# wait for tasks to complete
processed = [r.get() for r in results]

Thank you for the help :)

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
Danvdb
  • 103
  • 2
  • 13
  • 2
    Don't tag this with python 2 if you are using python 3. – juanpa.arrivillaga Mar 10 '17 at 18:24
  • 1
    Also, the error message seems pretty clear, you are using a string where it wants a bytes-like object. Whatever string you are passing, pass it `bytes(my_string, encoding=)` instead. Probably, for the encoding you want `'utf8'`. Or just `my_string.encode()` – juanpa.arrivillaga Mar 10 '17 at 18:24
  • @juanpa.arrivillaga I tried to do this already : r.get().encode() or the other but it shows the same error. What could I do else ? Thank you for the help ! – Danvdb Mar 10 '17 at 18:35
  • This may come as a shock, but I have *no idea* what your code is doing, what the names refer to, etc. From what I can tell, you probably want to `encode` whatever you are passing to `map.run` in `.map_async` – juanpa.arrivillaga Mar 10 '17 at 18:40

0 Answers0