I'm trying to parse some Java code in Python using ANTLRv4. I've tried to follow this post, but I get the following error:
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/antlr/proto_antlr.py", line 14, in <module>
main()
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/antlr/proto_antlr.py", line 9, in main
tree = parser.compilationUnit()
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/antlr/Java8Parser.py", line 4182, in compilationUnit
self.enterRule(localctx, 62, self.RULE_compilationUnit)
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/lib/python3.8/site-packages/antlr4/Parser.py", line 374, in enterRule
self._ctx.start = self._input.LT(1)
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/lib/python3.8/site-packages/antlr4/CommonTokenStream.py", line 62, in LT
self.lazyInit()
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/lib/python3.8/site-packages/antlr4/BufferedTokenStream.py", line 187, in lazyInit
self.setup()
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/lib/python3.8/site-packages/antlr4/BufferedTokenStream.py", line 190, in setup
self.sync(0)
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/lib/python3.8/site-packages/antlr4/BufferedTokenStream.py", line 112, in sync
fetched = self.fetch(n)
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/lib/python3.8/site-packages/antlr4/BufferedTokenStream.py", line 124, in fetch
t = self.tokenSource.nextToken()
File "/home/xxxxxxx/xxxxxxx/xxxxxxx/lib/python3.8/site-packages/antlr4/Lexer.py", line 130, in nextToken
self._tokenStartLine = self._interp.line_number
AttributeError: 'LexerATNSimulator' object has no attribute 'line_number'
I can't figure out what I'm doing wrong. The file I'm trying to parse is proper Java, it's extracted from the docker-maven-plugin package. I've tried with other files, but I get the same error.
Any idea ?
Actually it was just a problem of violent refactorization... I've changed line to line_number in my code, and it actually changed it in librairies too. Changing it back to line cleared the problem.
Thanks to #Thomas Kläger for making me realize it.
Related
I just installed the streamlit package. When I try to run 'streamlit hello' I get the following error:
(base) C:\>streamlit hello Traceback (most recent call last):
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\runpy.py",
line 193, in _run_module_as_main "__main__", mod_spec)
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\runpy.py",
line 85, in _run_code exec(code, run_globals)
File "C:\Users\s158539\AppData\Local\Continuum\anaconda3\Scripts\streamlit.exe\__main__.py",
line 5, in <module>
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\__init__.py",
line 121, in <module> from streamlit.DeltaGenerator import DeltaGenerator as _DeltaGenerator
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\DeltaGenerator.py",
line 33, in <module> from streamlit import caching
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\caching.py",
line 38, in <module> from streamlit.hashing import CodeHasher
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\hashing.py",
line 36, in <module> from streamlit.folder_black_list import FolderBlackList
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\folder_black_list.py",
line 39, in <module> if config.get_option("global.developmentMode"):
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\config.py",
line 94, in get_option parse_config_file()
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\config.py",
line 877, in parse_config_file _update_config_with_toml(file_contents, filename)
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\config.py",
line 799, in _update_config_with_toml parsed_config_file = toml.loads(raw_toml)
File "c:\users\s158539\appdata\local\continuum\anaconda3\lib\site-packages\toml\decoder.py",
line 379, in loads original, pos) toml.decoder.TomlDecodeError: Key group not on a line by itself. (line 1 column 1 char
Does anyone know how to solve this error?
Thank you in advance!
Just delete the config.toml file which can be found in the directory where you have installed streamlit.
I also got the same error while I tried to run the 'streamlit' command.
So, what I did is track in the code entirely to see from where I can find this 'config.toml' and simply deleted the file.
The path for 'config.toml' file in Windows is: C:users/{username}/.streamlit/config.toml
Delete this file and it will solve the error.
If you are not able to locate your .streamlit directory
Run streamlit cache clear
Output :
Nothing to clear at {Username}\{path}\.streamlit\cache.
You will get output similar to this which will tell you where is your .streamlit directory exactly.
Take this path before the cache part
cd {Username}\{path}\.streamlit
You'll be able to see config.toml here just delete that file.
The Streamlit forum has this discussion topic: https://discuss.streamlit.io/t/toml-docoder-error/1400/10 that discusses this. Hope this helps!
delete the content of config.toml file which is
in C:\Users\username.streamlit
Do you have a setup.sh file? What's the content inside it?
maybe you will just have to put the content of setup.sh everything in 1 line like this
[server]\nheadless = true\nenableCORS=false\nport = \n
my problem was similar, not exactly like this. so I hope it works!
I am running a bioinformatics software to create a custom gtf file. I am not sure how details on bioinformatics is relevant here.
I am a biologist so merely only have basic understanding of computer programs. I have been able to work out several errors, but this one makes no sense to me.
The program runs for a while and provides a required output, but when 25% of the program has run, it give the following error:
Traceback (most recent call last):
File "/home/everestial007/anaconda2/bin/g2gtools", line 4, in <module>
__import__('pkg_resources').run_script('g2gtools==0.1.27', 'g2gtools')
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/setuptools-20.3-py2.7.egg/pkg_resources/__init__.py", line 726, in run_script
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/setuptools-20.3-py2.7.egg/pkg_resources/__init__.py", line 1484, in run_script
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/g2gtools-0.1.27-py2.7.egg/EGG-INFO/scripts/g2gtools", line 117, in <module>
G2GToolsApp()
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/g2gtools-0.1.27-py2.7.egg/EGG-INFO/scripts/g2gtools", line 75, in __init__
getattr(self, args.command)()
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/g2gtools-0.1.27-py2.7.egg/EGG-INFO/scripts/g2gtools", line 78, in convert
g2gtools.g2g_commands.command_convert(sys.argv[2:], self.script_name + ' convert')
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/g2gtools-0.1.27-py2.7.egg/g2gtools/g2g_commands.py", line 89, in command_convert
file_convert(args.chain, args.input, args.output, args.format, args.reverse)
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/g2gtools-0.1.27-py2.7.egg/g2gtools/g2g.py", line 62, in file_convert
convert_gtf_file(chain_file=chain_file, input_file=input_file, output_file=output_file, reverse=reverse)
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/g2gtools-0.1.27-py2.7.egg/g2gtools/gtf.py", line 156, in convert_gtf_file
for record in gtf_file:
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/g2gtools-0.1.27-py2.7.egg/g2gtools/gtf.py", line 49, in next
self.current_record = parse_gtf_line(self.current_line)
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/g2gtools-0.1.27-py2.7.egg/g2gtools/gtf.py", line 101, in parse_gtf_line
'attributes': parse_attributes(elem[8])
File "/home/everestial007/anaconda2/lib/python2.7/site-packages/g2gtools-0.1.27-py2.7.egg/g2gtools/gtf.py", line 67, in parse_attributes
if val[0] == '"':
IndexError: string index out of range***
I have been able to navigate to the corresponding folders, find the appropriate files, open it and locate the particular lines and messages.
1) I am not clear how and why the lines from different sub-directories related. What is the error message trying to say?
2) I am getting "IndexError: string index out of range" at the end? what does it mean? I am thinking there is something wrong with the coding in the line if val[0] == '"':
I've been using keepass and libkeepass to access the key database via Python. Although the code works on linux it does not work on Windows, I receive this error relating to the keyfile:
with libkeepass.open(db_path, keyfile) as kdb:
File "C:\Python27\lib\contextlib.py", line 17, in __enter__
return self.gen.next()
File "build\bdist.win-amd64\egg\libkeepass\__init__.py", line 33, in open
File "build\bdist.win-amd64\egg\libkeepass\kdb4.py", line 380, in __init__
File "build\bdist.win-amd64\egg\libkeepass\kdb4.py", line 54, in __init__
File "build\bdist.win-amd64\egg\libkeepass\common.py", line 137, in __init__
File "build\bdist.win-amd64\egg\libkeepass\kdb4.py", line 383, in read_from
File "build\bdist.win-amd64\egg\libkeepass\kdb4.py", line 72, in read_from
File "build\bdist.win-amd64\egg\libkeepass\common.py", line 143, in read_from
File "build\bdist.win-amd64\egg\libkeepass\kdb4.py", line 191, in _decrypt
IOError: Master key invalid.
I had quite a bit of trouble getting libkeepass installed on windows as opposed to linux. Not sure if this effecting it, the library loads fine it just doesn't seem to be able to use the keyfile.
I'm open to suggestions for a better key database that has a more robust python API if one exists, it needs to be a free to use piece of software?
TIA
I am trying to open my tryton client but it is not working
the snapshot of my problem :
the text of the problem is:
File "./tryton", line 66, in <module>
tryton.client.TrytonClient().run()
File "/home/ghassen/work/tryton/tryton/client.py", line 101, in run
main.sig_login()
File "/home/ghassen/work/tryton/tryton/gui/main.py", line 910, in sig_login
res = DBLogin().run()
File "/home/ghassen/work/tryton/tryton/gui/window/dblogin.py", line 579, in run
if (self.profiles.get(profile_name, sectionname)
File "/usr/lib/python2.7/ConfigParser.py", line 618, in get
raise NoOptionError(option, section)
Tryton has a profile file where it saves the know connections, and from the error it seems that file is corrupted. You can find this file under ~/.config/tryton/x.y/profiles.cfg where x.y corresponds to you version number.
If you don't have any saved profile, you can remove this file and the client will recreate them when started another time.
I recently started writing a simple client using the Blogger API to do some basic posting I implemented the client in Python and used the example code verbatim from the Blogger Developer's Guide to login, get the blog id, and make a new post. I ran the script and everything went fine until I got to this line:
return blogger_service.Post(entry, '/feeds/%s/posts/default' % blog_id)
I got the error message:
Traceback (most recent call last):
File "cs1121post.py", line 38, in <module>
cs1121post()
File "cs1121post.py", line 33, in cs1121post
return blogger_service.Post(entry, '/feeds/%s/posts/default' % blog_id)
File "/usr/local/lib/python2.7/dist-packages/gdata/service.py", line 1236, in Post
media_source=media_source, converter=converter)
File "/usr/local/lib/python2.7/dist-packages/gdata/service.py", line 1322, in PostOrPut
headers=extra_headers, url_params=url_params)
File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 93, in optional_warn_function
return f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/atom/service.py", line 176, in request
content_length = CalculateDataLength(data)
File "/usr/local/lib/python2.7/dist-packages/atom/service.py", line 736, in CalculateDataLength
return len(str(data))
File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 377, in __str__
return self.ToString()
File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 374, in ToString
return ElementTree.tostring(self._ToElementTree(), encoding=string_encoding)
File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 369, in _ToElementTree
self._AddMembersToElementTree(new_tree)
File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 331, in _AddMembersToElementTree
member._BecomeChildElement(tree)
File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 357, in _BecomeChildElement
self._AddMembersToElementTree(new_child)
File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 342, in _AddMembersToElementTree
ExtensionContainer._AddMembersToElementTree(self, tree)
File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 224, in _AddMembersToElementTree
tree.text = self.text.decode(MEMBER_STRING_ENCODING)
AttributeError: 'list' object has no attribute 'decode'
By which I'm taking it that ElementTree is at fault here. I installed ElementTree via
sudo python setup.py install
in case it matters. Is there some known incompatibility between ElementTree and Python v2.7.1? Has this happened to anybody else and how did you get it working? If you need any additional information, please reply to the thread. All the source code that is relevant is basically just the example code from the Developers Guide mentioned above. I haven't modified that at all (not even the variable names). Any input is greatly appreciated.
The stacktrace is actually pretty clear about this: You're calling decode() on a list instead of a tree element. Try getting the first element from the list and calling decode() on that:
firsttext = self.text[0].decode(MEMBER_STRING_ENCODING)