jupyter notebook with R cannot display specific Kanji (multibyte characters) - python

I am using jupyter notebook, but R kernel(IRkernel) sometimes die when inputting Kanji(japanese multibyte chars).
I've tried a few Kanji, and found that IRkernel dies when using specific Kanji characters. For example, '十', '能', '表', etc.
Above image is R concole. Below is Python console.
It doesen't work with R kernel only.
  
[I 12:44:58.387 LabApp] Kernel started: 9bbe39ea-ef5a-40c3-ae71-fa071874fc79
-- Attaching packages --------------------------------------- tidyverse 1.2.1 --
tibble 1.4.2 purrr 0.2.5
tidyr 0.8.2 dplyr 0.7.8
readr 1.1.1 forcats 0.3.0
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x dplyr::between() masks data.table::between()
x readr::col_factor() masks scales::col_factor()
x purrr::discard() masks scales::discard()
x dplyr::first() masks data.table::first()
x dplyr::last() masks data.table::last()
x purrr::transpose() masks data.table::transpose()
[I 12:45:00.626 LabApp] Adapting to protocol v5.0 for kernel 9bbe39ea-ef5a-40c3-ae71-fa071874fc79
[E 12:45:09.377 LabApp] Uncaught exception in ZMQStream callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
callback(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 376, in record_activity
msg = session.deserialize(fed_msg_list)
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 933, in deserialize
message['content'] = self.unpack(msg_list[4])
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 105, in <lambda>
json_unpacker = lambda s: jsonapi.loads(s)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\utils\jsonapi.py", line 56, in loads
return jsonmod.loads(s, **kwargs)
File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 25 (char 24)
[E 12:45:09.377 LabApp] Uncaught exception in zmqstream callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 450, in _handle_events
self._handle_recv()
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 480, in _handle_recv
self._run_callback(callback, msg)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
callback(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 376, in record_activity
msg = session.deserialize(fed_msg_list)
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 933, in deserialize
message['content'] = self.unpack(msg_list[4])
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 105, in <lambda>
json_unpacker = lambda s: jsonapi.loads(s)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\utils\jsonapi.py", line 56, in loads
return jsonmod.loads(s, **kwargs)
File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 25 (char 24)
Exception in callback BaseAsyncIOLoop._handle_events(1596, 1)
handle: <Handle BaseAsyncIOLoop._handle_events(1596, 1)>
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\asyncio\events.py", line 145, in _run
self._callback(*self._args)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 117, in _handle_events
handler_func(fileobj, events)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 450, in _handle_events
self._handle_recv()
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 480, in _handle_recv
self._run_callback(callback, msg)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
callback(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 376, in record_activity
msg = session.deserialize(fed_msg_list)
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 933, in deserialize
message['content'] = self.unpack(msg_list[4])
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 105, in <lambda>
json_unpacker = lambda s: jsonapi.loads(s)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\utils\jsonapi.py", line 56, in loads
return jsonmod.loads(s, **kwargs)
File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 25 (char 24)
[E 12:45:09.377 LabApp] Uncaught exception GET /api/kernels/9bbe39ea-ef5a-40c3-ae71-fa071874fc79/channels?session_id=89b50480637cb8ce56024a508a3e4c34 (::1)
HTTPServerRequest(protocol='http', host='localhost:9999', method='GET', uri='/api/kernels/9bbe39ea-ef5a-40c3-ae71-fa071874fc79/channels?session_id=89b50480637cb8ce56024a508a3e4c34', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\web.py", line 1499, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File "<string>", line 4, in raise_exc_info
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 315, in wrapped
ret = fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 196, in <lambda>
self.on_recv(lambda msg: callback(self, msg), copy=copy)
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\kernels\handlers.py", line 313, in _on_zmq_reply
msg = self.session.deserialize(fed_msg_list)
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 933, in deserialize
message['content'] = self.unpack(msg_list[4])
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 105, in <lambda>
json_unpacker = lambda s: jsonapi.loads(s)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\utils\jsonapi.py", line 56, in loads
return jsonmod.loads(s, **kwargs)
File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 25 (char 24)
And this code works on native R environment fine, so I think this is IRkernel problem.
Thanks.
*Version
OS:Win 10
jupyter-lab:0.32.1
IRkernel:'0.8.14.9000'

Related

JSONDecodeError Issue when running doit tests

This is what I am running with doit.
def task_tests() -> dict:
"""Runs all tests."""
return {
"actions": ["poetry run pytest"],
}
and When I run it I get this error
doit tests
Traceback (most recent call last):
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/doit_cmd.py", line 294, in run
return command.parse_execute(args)
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/cmd_base.py", line 150, in parse_execute
return self.execute(params, args)
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/cmd_base.py", line 570, in execute
return self._execute(**exec_params)
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/cmd_run.py", line 265, in _execute
return runner.run_all(self.control.task_dispatcher())
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/runner.py", line 254, in run_all
self.run_tasks(task_dispatcher)
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/runner.py", line 217, in run_tasks
if not self.select_task(node, task_dispatcher.tasks):
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/runner.py", line 118, in select_task
if node.ignored_deps or self.dep_manager.status_is_ignore(task):
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/dependency.py", line 594, in status_is_ignore
return self._get(task.name, "ignore:")
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/dependency.py", line 213, in get
self._db[task_id] = self.codec.decode(task_data.decode('utf-8'))
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/dependency.py", line 60, in decode
return self.decoder.decode(data)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 1359414 (char 1359413)
I can run other doit tasks but not tests. I can run this command from terminal without any error
I am using an apple MacBook pro [M1 chip]

InstaLoader simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I've been trying to fix this but couldn't find a fix anywhere, I'm using InstaLoader 4.5.5.
I am getting this error:
Traceback (most recent call last):
File "main.py", line 145, in <module>
attemptRoutine()
File "main.py", line 136, in attemptRoutine
routine()
File "main.py", line 90, in routine
scrapeVideos(username = IG_USERNAME,
File "/media/ubuntu/EE81-0482/Python/auto_Yt/scrape_videos.py", line 18, in scrapeVideos
L.login(username, password)
File "/home/ubuntu/.local/lib/python3.8/site-packages/instaloader/instaloader.py", line 483, in login
self.context.login(user, passwd)
File "/home/ubuntu/.local/lib/python3.8/site-packages/instaloader/instaloadercontext.py", line 224, in login
resp_json = login.json()
File "/usr/lib/python3/dist-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I've been trying to scrape videos from meme pages for a youtube channel, Code taken from:
automated_youtube_channel Github

error : json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

stock_df = pd.DataFrame()
stock = []
stock = yf.download(ticker, start= start_date, end= end_date, progress= False)
stock_df= stock_df.append(stock, sort= False)
stock_df['Symbol'] = ticker
Exception in thread Thread-4:
Traceback (most recent call last):
File "/opt/anaconda3/envs/learn-env/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/opt/anaconda3/envs/learn-env/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/multitasking/__init__.py", line 102, in _run_via_pool
return callee(*args, **kwargs)
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/yfinance/multi.py", line 166, in _download_one_threaded
data = _download_one(ticker, start, end, auto_adjust, back_adjust,
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/yfinance/multi.py", line 178, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/yfinance/base.py", line 155, in history
data = data.json()
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/opt/anaconda3/envs/learn-env/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/opt/anaconda3/envs/learn-env/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/opt/anaconda3/envs/learn-env/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

When I run this simple file I get this .json error

The code is so simple I don't know how the error can be solved. All the packages has been updated.
import datetime as dt
import yfinance as yf
ticker = 'MSFT'
start_date = dt.datetime(2020,1,1)
data = yf.download(ticker, start_date)
And the error is in .json, I don't have any ideas how this can be solved.
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/multitasking/__init__.py", line 102, in _run_via_pool
return callee(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/yfinance/multi.py", line 169, in _download_one_threaded
data = _download_one(ticker, start, end, auto_adjust, back_adjust,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/yfinance/multi.py", line 181, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/yfinance/base.py", line 157, in history
data = data.json()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 125: invalid continuation byte

I am reading in a file with 50000 rows and values:
2.711569 2.295490 4.141002
...
And numpy.loadtxt does a good job reading them and doing some calculations. Once i call my function :
c = setupc(2,n) # setups of cov matrix
with n = 499999
it leads me to the dispatcher:
def _compile_for_args(self, *args, **kws):
"""
For internal use. Compile a specialized version of the function
for the given *args* and *kws*, and return the resulting callable.
"""
assert not kws
def error_rewrite(e, issue_type):
"""
Rewrite and raise Exception `e` with help supplied based on the
specified issue_type.
"""
if config.SHOW_HELP:
help_msg = errors.error_extras[issue_type]
e.patch_message('\n'.join((str(e).rstrip(), help_msg)))
if config.FULL_TRACEBACKS:
raise e
else:
reraise(type(e), e, None)
argtypes = []
for a in args:
if isinstance(a, OmittedArg):
argtypes.append(types.Omitted(a.value))
else:
argtypes.append(self.typeof_pyval(a))
try:
return self.compile(tuple(argtypes))
and gives the error:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\lib\site-packages\spyder_kernels\console\__main__.py", line 11, in <module>
start.main()
File "C:\Anaconda3\lib\site-packages\spyder_kernels\console\start.py", line 318, in main
kernel.start()
File "C:\Anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 583, in start
self.io_loop.start()
File "C:\Anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 153, in start
self.asyncio_loop.run_forever()
File "C:\Anaconda3\lib\asyncio\base_events.py", line 538, in run_forever
self._run_once()
File "C:\Anaconda3\lib\asyncio\base_events.py", line 1782, in _run_once
handle._run()
File "C:\Anaconda3\lib\asyncio\events.py", line 100, in _run
self._loop.call_exception_handler(context)
File "C:\Anaconda3\lib\asyncio\base_events.py", line 1647, in call_exception_handler
exc_info=True)
File "C:\Anaconda3\lib\logging\__init__.py", line 1407, in error
self._log(ERROR, msg, args, **kwargs)
File "C:\Anaconda3\lib\logging\__init__.py", line 1514, in _log
self.handle(record)
File "C:\Anaconda3\lib\logging\__init__.py", line 1524, in handle
self.callHandlers(record)
File "C:\Anaconda3\lib\logging\__init__.py", line 1594, in callHandlers
lastResort.handle(record)
File "C:\Anaconda3\lib\logging\__init__.py", line 894, in handle
self.emit(record)
File "C:\Anaconda3\lib\logging\__init__.py", line 1033, in emit
self.handleError(record)
File "C:\Anaconda3\lib\logging\__init__.py", line 947, in handleError
traceback.print_exception(t, v, tb, None, sys.stderr)
File "C:\Anaconda3\lib\traceback.py", line 104, in print_exception
type(value), value, tb, limit=limit).format(chain=chain):
File "C:\Anaconda3\lib\traceback.py", line 521, in __init__
self._load_lines()
File "C:\Anaconda3\lib\traceback.py", line 533, in _load_lines
self.__context__._load_lines()
File "C:\Anaconda3\lib\traceback.py", line 533, in _load_lines
self.__context__._load_lines()
File "C:\Anaconda3\lib\traceback.py", line 533, in _load_lines
self.__context__._load_lines()
[Previous line repeated 14 more times]
File "C:\Anaconda3\lib\traceback.py", line 531, in _load_lines
frame.line
File "C:\Anaconda3\lib\traceback.py", line 285, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
File "C:\Anaconda3\lib\linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "C:\Anaconda3\lib\linecache.py", line 47, in getlines
return updatecache(filename, module_globals)
File "C:\Anaconda3\lib\linecache.py", line 137, in updatecache
lines = fp.readlines()
File "C:\Anaconda3\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 125: invalid continuation byte
I hope somebody can help me
EDIT:
Function setupc:
def setupc(m,n):
c = np.zeros((m,m))
for i in range(1,m+1):
for j in range(1,m+1):
# Heaviside
if (i + j - n - 2 >= 0):
heav = 1.0
else:
heav = 0.0
c[i-1,j-1] = (
2.*min(i,j) * (1.+3.*i*j - min(i,j)**2) / (n - min(i,j) +1)
+ (min(i,j)**2 - min(i,j)**4) / ((n-i+1.)*(n-j+1.))
+ heav * ((n+1.-i-j)**4 - (n+1.-i-j)**2) / ((n-i+1.)*(n-j+1.))
)
return c

Categories