Dash traceback not leading to any line in my code - python

I am working on my first Dash app. I am getting the following error:
"Cannot set a frame with no defined index "
The issue is that the traceback doesn’t lead to any line in my code. It only goes through installed libraries:
Traceback (most recent call last):
File "C:\Users\LIAG8802\Documents\Procurement_analytics\venv\lib\site-packages\pandas\core\frame.py", line 3540, in _ensure_valid_index
value = Series(value)
File "C:\Users\LIAG8802\Documents\Procurement_analytics\venv\lib\site-packages\pandas\core\series.py", line 316, in __init__
data = SingleBlockManager(data, index, fastpath=True)
File "C:\Users\LIAG8802\Documents\Procurement_analytics\venv\lib\site-packages\pandas\core\internals\managers.py", line 1516, in __init__
block = make_block(block, placement=slice(0, len(axis)), ndim=1)
File "C:\Users\LIAG8802\Documents\Procurement_analytics\venv\lib\site-packages\pandas\core\internals\blocks.py", line 3284, in make_block
return klass(values, ndim=ndim, placement=placement)
File "C:\Users\LIAG8802\Documents\Procurement_analytics\venv\lib\site-packages\pandas\core\internals\blocks.py", line 2792, in __init__
super().__init__(values, ndim=ndim, placement=placement)
File "C:\Users\LIAG8802\Documents\Procurement_analytics\venv\lib\site-packages\pandas\core\internals\blocks.py", line 128, in __init__
"{mgr}".format(val=len(self.values), mgr=len(self.mgr_locs))
ValueError: Wrong number of items passed 3, placement implies 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\LIAG8802\Documents\Procurement_analytics\venv\lib\site-packages\pandas\core\frame.py", line 3543, in _ensure_valid_index
"Cannot set a frame with no defined index "
ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series
How can I know which line in my code is causing the error? Note that I found out what the problem was but I want to know how I could have traced it more easily.
EDIT: note that I cannot track the issue putting prints at several lines since the error pops out in the dash debug console, not in the anaconda console which does not crash

Related

How to debug the error message from a yapf formatting task?

I recently inherited a code base and am in the process of using yapf (and indirectly lib2to3) to format the code base. When I run the formatter I get the following output:
Traceback (most recent call last):
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/yapf_api.py", line 183, in FormatCode
tree = pytree_utils.ParseCodeToTree(unformatted_source)
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/pytree_utils.py", line 125, in ParseCodeToTree
tree = parser_driver.parse_string(code, debug=False)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/driver.py", line 103, in parse_string
return self.parse_tokens(tokens, debug)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/driver.py", line 71, in parse_tokens
if p.addtoken(type, value, (prefix, start)):
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/parse.py", line 119, in addtoken
ilabel = self.classify(type, value, context)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/parse.py", line 175, in classify
raise ParseError("bad token", type, value, context)
lib2to3.pgen2.parse.ParseError: bad token: type=58, value='ִ', context=('', (325, 19))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/module/venv/lib/python3.9/site-packages/yapf/__init__.py", line 225, in _FormatFile
reformatted_code, encoding, has_change = yapf_api.FormatFile(
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/yapf_api.py", line 96, in FormatFile
reformatted_source, changed = FormatCode(
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/yapf_api.py", line 186, in FormatCode
raise errors.YapfError(errors.FormatErrorMsg(e))
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/errors.py", line 37, in FormatErrorMsg
return '{}:{}:{}: {}'.format(e.args[1][0], e.args[1][1], e.args[1][2], e.msg)
IndexError: tuple index out of range
It seems that the error arises from a unicode character from the lib2to3.pgen2.parse.ParseError: bad token: type=58, value='ִ', context=('', (325, 19)) error, though I am unsure how to 1) find the source of the error and 2) how to fix it if I do find it.
As of now, I don't believe that unicode character is in the codebase; though, the codebase is fairly large so it is entirely possible that I am just missing it somewhere.
Does anyone have any experience parsing these types of errors or can point me in the right direction?
I found a few github issues describing this type of error, but they remain Open with no direction on finding the source.

twitterImgBot stops working after some hours

I'm trying to get this, https://github.com/joaquinlpereyra/twitterImgBot, to work
and it works and it seems ok.
But after some hours, it stops working and this error comes up:
*python3 twitterbot.py
Traceback (most recent call last):
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 118, in build_path
value = quote(self.session.params[name])
KeyError: 'id'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "twitterbot.py", line 209, in <module>
main()
File "twitterbot.py", line 200, in main
orders()
File "twitterbot.py", line 118, in orders
timeline.delete_tweet_by_id(tweet.in_reply_to_status_id, api)
File "/home/user/Skrivebord/twitterboot/lo/bot/timeline.py", line 12, in delete_tweet_by_id
api.destroy_status(id_to_delete)
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 245, in _call
method = APIMethod(args, kwargs)
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 71, in __init__
self.build_path()
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 120, in build_path
raise TweepError('No parameter value found for path variable: %s' % name)
tweepy.error.TweepError: No parameter value found for path variable: id*
It seems like the Python has some problem because if I make a new install on a another PC it works for some hours and then stops.
Strange.
This is likely because tweet is not in reply to a status, so has an in_reply_to_status_id attribute that's None, so API.destroy_status is called with an id of None.

list out of range error when python-docx reads a table of which the border's not aligned

I am parsing a table (which looks like the image below) in Word docx file by using python-docx. But when it reads the table below it throws an error.
I've noticed that there is a tiny "crack" at the right-end border of the table as I circled red in the picture. If I manually align the right-end border, my code will be fine. But isn't there a clever way to solve it?
from docx import Document
document = Document(u'D:\\1.docx')
tables = document.tables
print(tables[0].rows[0].cells[0].text)
The error is:
Traceback (most recent call last):
File "C:\Users\lenovo\Anaconda2\envs\py3\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-168-61cbbaa7e1a8>", line 1, in <module>
tables[0].rows[0].cells[0].text
File "C:\Users\lenovo\Anaconda2\envs\py3\lib\site-packages\docx\table.py", line 384, in cells
return tuple(self.table.row_cells(self._index))
File "C:\Users\lenovo\Anaconda2\envs\py3\lib\site-packages\docx\table.py", line 106, in row_cells
return self._cells[start:end]
File "C:\Users\lenovo\Anaconda2\envs\py3\lib\site-packages\docx\table.py", line 173, in _cells
cells.append(cells[-col_count])
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\lenovo\Anaconda2\envs\py3\lib\site-packages\IPython\core\interactiveshell.py", line 2808, in run_ast_nodes
if self.run_code(code, result):
File "C:\Users\lenovo\Anaconda2\envs\py3\lib\site-packages\IPython\core\interactiveshell.py", line 2879, in run_code
self.showtraceback(running_compiled_code=True)
TypeError: showtraceback() got an unexpected keyword argument 'running_compiled_code'
Can someone help me?

After starting spyder: ImportError: cannot import name 'quick_guide'

When I start spyder the internal console pops up and gives the following "traceback":
>>> WARNING:traitlets:kernel died: 6.001837253570557
Traceback (most recent call last):
File "C:\...\lib\site-packages\traitlets\traitlets.py", line 528, in get
value = obj._trait_values[self.name]
KeyError: 'banner'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\...\lib\site-packages\qtconsole\base_frontend_mixin.py", line 163, in _dispatch
handler(msg)
File "C:\...\lib\site-packages\qtconsole\jupyter_widget.py", line 296, in _handle_kernel_info_reply
super(JupyterWidget, self)._started_channels()
File "C:\...\lib\site-packages\qtconsole\frontend_widget.py", line 617, in _started_channels
self.reset(clear=True)
File "C:\...\lib\site-packages\qtconsole\frontend_widget.py", line 661, in reset
self._append_plain_text(self.banner)
File "C:\...\lib\site-packages\traitlets\traitlets.py", line 556, in __get__
return self.get(obj, cls)
File "C:\...\lib\site-packages\traitlets\traitlets.py", line 535, in get
value = self._validate(obj, dynamic_default())
File "C:\...\lib\site-packages\spyder\widgets\ipythonconsole\shell.py", line 280, in _banner_default
return self.long_banner()
File "C:\...\lib\site-packages\spyder\widgets\ipythonconsole\shell.py", line 91, in long_banner
from IPython.core.usage import quick_guide
ImportError: cannot import name 'quick_guide'
The IPython console works without problems, it is just missing the "introduction text" (python version, help-commands).
Can I just ignore this exception or is there a way to fix this manually?
(Spyder developer here) This was fixed in Spyder 3.1.4 (just released). Please update to fix it.
To fix the exception manually one needs to change the last mentioned file in the traceback. In this case this one:
File "C:\...\lib\site-packages\spyder\widgets\ipythonconsole\shell.py", line 91, in long_banner
from IPython.core.usage import quick_guide
ImportError: cannot import name 'quick_guide'
and change quick_guide to quick_reference as quick_guide. One may need to restart Spyder but then the Exception disappeared.
I solved:
Only use conda install spyder=3.1.4 in your conda env.
Regards.

Error while adding new code after 3200 lines in Python using IDLE

I have a python program which works fine and has 3200 lines of code. When I try to add new lines of code in it the following error appears:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__
return self.func(*args)
File "C:\Python24\lib\idlelib\ScriptBinding.py", line 142, in run_module_event
code = self.checksyntax(filename)
File "C:\Python24\lib\idlelib\ScriptBinding.py", line 101, in checksyntax
return compile(source, filename, "exec")
SystemError: com_backpatch: offset too large

Categories