After importing nltk nltk.download() is not working - python

This error messages comes up every time
import nltk
nltk.download()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\Lib\site-packages\nltk\downloader.py", line 655, in download
self._interactive_download()
File "C:\Python34\Lib\site-packages\nltk\downloader.py", line 974, in _interactive_download
DownloaderGUI(self).mainloop()
File "C:\Python34\Lib\site-packages\nltk\downloader.py", line 1234, in __init__
self._fill_table()
File "C:\Python34\Lib\site-packages\nltk\downloader.py", line 1530, in _ fill_table
items = self._ds.collections()
File "C:\Python34\Lib\site-packages\nltk\downloader.py", line 499, in collections
self._update_index()
File "C:\Python34\Lib\site-packages\nltk\downloader.py", line 825, in _update_index
ElementTree.parse(compat.urlopen(self._url)).getroot())
File "C:\Python34\lib\xml\etree\ElementTree.py", line 1187, in parse
tree.parse(source, parser)
File "C:\Python34\lib\xml\etree\ElementTree.py", line 598, in parse
self._root = parser._parse_whole(source)
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0
And the downloader window opens without anything or list. I have checked downloader.py and it contains the right and new default link of the corpora.
I am using Windows standard edition.

Related

python lxml in docker: "Document is empty" while parsing

Why this code is working without issues on my mac with any version of python, requests and lxml, but doesn't work in any docker container? i tried everything(
it just fails on 34533 line (discovered by printing el.sourceline)
from requests import get
from lxml import etree
r = get('https://printbar.ru/synsfiles/yandex/market/idrr_full.xml')
with open('test.xml', 'wb') as f:
f.write(r.content)
tree = etree.iterparse(source='test.xml', events=('end',))
for (ev, el) in tree:
continue
print('ok')
https://printbar.ru/synsfiles/yandex/market/idrr_full.xml seems completely valid and works locally on any of my macs...
i tried ubuntu, alpine, several python containers even with prebuilt lxml, nothing helped. I expected that parsing this file won't throw this error in the middle of parsing:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "src/lxml/iterparse.pxi", line 210, in lxml.etree.iterparse.__next__
File "src/lxml/iterparse.pxi", line 195, in lxml.etree.iterparse.__next__
File "src/lxml/iterparse.pxi", line 230, in lxml.etree.iterparse._read_more_events
File "src/lxml/parser.pxi", line 1376, in lxml.etree._FeedParser.feed
File "src/lxml/parser.pxi", line 606, in lxml.etree._ParserContext._handleParseResult
File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError
File "test.xml", line 1
lxml.etree.XMLSyntaxError: Document is empty, line 1, column 1
xmllint says that there is encoding error, but it works locally on mac...) HOW?) i want it dockerized!)

Python Kivy UnicodeEncodeError

I am new to Kivy and I am trying to do my first app with using Kivy. But in my first attemp I failed and unfortunately I couldn't find any answer from anywhere.
my code is:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class EpicApp(App):
def build(self):
return Label(text="hi there")
if __name__ == "__main__":
EpicApp().run()
My error is simply:
UnicodeEncodeError: 'charmap' codec can't encode character '\u0131' in position 280: character maps to < undefined>
my whole error code is:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/burak/Desktop/Stuff/python for fun/kivy basics/kivyapp.py", line 13, in <module>
EpicApp().run()
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\app.py", line 829, in run
root = self.build()
File "C:/Users/burak/Desktop/Stuff/python for fun/kivy basics/kivyapp.py", line 9, in build
return Label(text="hi there")
File "kivy\_event.pyx", line 188, in kivy._event.EventDispatcher.__cinit__
File "kivy\properties.pyx", line 447, in kivy.properties.Property.link
File "kivy\properties.pyx", line 632, in kivy.properties.NumericProperty.init_storage
File "kivy\properties.pyx", line 418, in kivy.properties.Property.init_storage
File "kivy\properties.pyx", line 655, in kivy.properties.NumericProperty.convert
File "kivy\properties.pyx", line 663, in kivy.properties.NumericProperty.parse_str
File "kivy\properties.pyx", line 670, in kivy.properties.NumericProperty.parse_list
File "kivy\properties.pyx", line 296, in kivy.properties.dpi2px
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\utils.py", line 505, in __get__
retval = self.func(inst)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\metrics.py", line 174, in dpi
EventLoop.ensure_window()
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\base.py", line 123, in ensure_window
import kivy.core.window # NOQA
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\core\window\__init__.py", line 2068, in <module>
Window = core_select_lib('window', window_impl, True)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\core\__init__.py", line 103, in core_select_lib
'identify potential causes\n{1}'.format(category.capitalize(), err))
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 1425, in critical
self._log(CRITICAL, msg, args, **kwargs)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 1514, in _log
self.handle(record)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 1524, in handle
self.callHandlers(record)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 1586, in callHandlers
hdlr.handle(record)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 894, in handle
self.emit(record)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\logger.py", line 247, in emit
self._write_message(message)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\logger.py", line 218, in _write_message
stream.write(fs % msg)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u0131' in position 280: character maps to <undefined>
edit: When I tried to open file from cmd I get this error.(Normally I am using PyCharm)
[ERROR ] [Clock ] Unable to import kivy._clock. Have you perhaps forgotten to compile kivy? Kivy contains Cython code which needs to be compiled. A missing kivy._clock often indicates the Cython code has not been compiled. Please follow the installation instructions and make sure to compile Kivy Traceback (most recent call last): File "kivyapp.py", line 2, in <module>
from kivy.app import App File "C:\Users\burak\AppData\Roaming\Python\Python37\site-packages\kivy\app.py", line 319, in <module>
from kivy.base import runTouchApp, stopTouchApp File "C:\Users\burak\AppData\Roaming\Python\Python37\site-packages\kivy\base.py", line 26, in <module>
from kivy.clock import Clock File "C:\Users\burak\AppData\Roaming\Python\Python37\site-packages\kivy\clock.py", line 363, in <module>
from kivy._clock import CyClockBase, ClockEvent, FreeClockEvent, \ ModuleNotFoundError: No module named 'kivy._clock'

Can etree.XMLParser in recover mode still throw a parse error?

I have a utility method that parses XML using a parser created as etree.XMLParser(recover=True). I would like to test failure scenarios in a unit test. Except for empty input throwing an lxml.etree.XMLSyntaxError, I can't seem to break the parser.
My question is: is it possible to construct a StringIO or BytesIO input for this parser such that the parser throws a parse error?
Here's some examples (tested with Python 3.5 and lxml 4.3.3):
from io import BytesIO
from lxml import etree
def parse(xml):
parser = etree.XMLParser(recover=True)
elem = etree.parse(BytesIO(xml), parser)
print(etree.tostring(elem))
parse(b'<broken<') # prints b'<broken/>'
parse(b'</lf|\jf>') # prints None
parse('<?xml encoding="ascii"?><foo>æøå</foo>'.encode('utf-8')) # prints b'<foo/>'
parse(b'') # Throws lxml.etree.XMLSyntaxError
If I slap a NULL character at the beginning of any of the bad inputs you show that don't raise an error, I do get an error. For instance:
parse(b'\0<broken<')
produces:
Traceback (most recent call last):
File "test.py", line 13, in <module>
parse(b'\0<broken<') # prints b'<broken/>'
File "test.py", line 9, in parse
elem = etree.parse(BytesIO(xml), parser)
File "src/lxml/etree.pyx", line 3435, in lxml.etree.parse
File "src/lxml/parser.pxi", line 1857, in lxml.etree._parseDocument
File "src/lxml/parser.pxi", line 1877, in lxml.etree._parseMemoryDocument
File "src/lxml/parser.pxi", line 1765, in lxml.etree._parseDoc
File "src/lxml/parser.pxi", line 1127, in lxml.etree._BaseParser._parseDoc
File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 640, in lxml.etree._raiseParseError
File "<string>", line 1
lxml.etree.XMLSyntaxError: Document is empty, line 1, column 1
Isn't it because you are using recover=True?
recover - try hard to parse through broken XML
I changed recover=False and I get:
Traceback (most recent call last):
File "./foo.py", line 11, in <module>
parse(b'<broken<') # prints b'<broken/>'
File "./foo.py", line 7, in parse
elem = etree.parse(BytesIO(xml), parser)
File "src/lxml/etree.pyx", line 3435, in lxml.etree.parse
File "src/lxml/parser.pxi", line 1857, in lxml.etree._parseDocument
File "src/lxml/parser.pxi", line 1877, in lxml.etree._parseMemoryDocument
File "src/lxml/parser.pxi", line 1765, in lxml.etree._parseDoc
File "src/lxml/parser.pxi", line 1127, in lxml.etree._BaseParser._parseDoc
File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 640, in lxml.etree._raiseParseError
File "<string>", line 1
lxml.etree.XMLSyntaxError: error parsing attribute name, line 1, column 8
Am I missing something?

Some data on this page is currently being calculated, and the page will be refreshed automatically

I just installed pootle and I'm having this messagge "Some data on this page is currently being calculated, and the page will be refreshed automatically x seconds". Upon going to the admin page, I found out that there is a failed job so I run on my command line pootle retry_failed_jobs.
And this is what it says :/
`DoesNotExist: Directory matching query does not exist.
Traceback (most recent call last):
File "/var/www/pootle/env/local/lib/python2.7/site-packages/rq/worker.py", line 568, in perform_job
rv = job.perform()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/rq/job.py", line 495, in perform
self._result = self.func(*self.args, **self.kwargs)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 683, in update_cache_job
instance._update_cache_job(keys, decrement)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 534, in _update_cache_job
create_update_cache_job_wrapper(p, keys_for_parent, decrement)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 693, in create_update_cache_job_wrapper
connection.on_commit(_create_update_cache_job)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/transaction_hooks/mixin.py", line 31, in on_commit
func()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 692, in _create_update_cache_job
create_update_cache_job(queue, instance, keys, decrement=decrement)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 707, in create_update_cache_job
last_job_key = instance.get_last_job_key()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 299, in get_last_job_key
key = self.get_cachekey()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/apps/pootle_translationproject/models.py", line 373, in get_cachekey
return self.directory.pootle_path
File "/var/www/pootle/env/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 572, in __get__
rel_obj = qs.get()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/django/db/models/query.py", line 357, in get
self.model._meta.object_name)
DoesNotExist: Directory matching query does not exist.
Traceback (most recent call last):
File "/var/www/pootle/env/local/lib/python2.7/site-packages/rq/worker.py", line 568, in perform_job
rv = job.perform()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/rq/job.py", line 495, in perform
self._result = self.func(*self.args, **self.kwargs)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 683, in update_cache_job
instance._update_cache_job(keys, decrement)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 534, in _update_cache_job
create_update_cache_job_wrapper(p, keys_for_parent, decrement)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 693, in create_update_cache_job_wrapper
connection.on_commit(_create_update_cache_job)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/transaction_hooks/mixin.py", line 31, in on_commit
func()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 692, in _create_update_cache_job
create_update_cache_job(queue, instance, keys, decrement=decrement)
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 707, in create_update_cache_job
last_job_key = instance.get_last_job_key()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/core/mixins/treeitem.py", line 299, in get_last_job_key
key = self.get_cachekey()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/pootle/apps/pootle_translationproject/models.py", line 373, in get_cachekey
return self.directory.pootle_path
File "/var/www/pootle/env/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 572, in __get__
rel_obj = qs.get()
File "/var/www/pootle/env/local/lib/python2.7/site-packages/django/db/models/query.py", line 357, in get
self.model._meta.object_name)
DoesNotExist: Directory matching query does not exist.
`
This actually happened when I deleted the language of the project using the admin panel, then suddenly somewhat deleted the folder of that language in the system. What I did is to create a new project and copy the translation files. So I didn't resolve the problem but I was able to remove the refreshing of data.
The stats in Pootle are managed by Redis. Pootle can sometimes get into a state where the stats are broken. Issues like broken files can cause this. You can clean up the stats using this guide.
I'd also report the situation and any tracebacks to the Pootle developers so that they can make the stats calculations more robust.

MemoryError on Python minidom

I'm having a weird MemoryError while parsing XML via minidom (ran on a server, file-path changed):
Traceback (most recent call last):
File "python.py", line 19, in <module>
xmldoc = minidom.parseString(unicode(data,errors='ignore'))
File "/usr/lib/python2.6/xml/dom/minidom.py", line 1928, in parseString
return expatbuilder.parseString(string)
File "/usr/lib/python2.6/xml/dom/expatbuilder.py", line 940, in parseString
return builder.parseString(string)
File "/usr/lib/python2.6/xml/dom/expatbuilder.py", line 223, in parseString
parser.Parse(string, True)
File "/usr/lib/python2.6/xml/dom/expatbuilder.py", line 753, in start_element_handler
_append_child(self.curNode, node)
File "/usr/lib/python2.6/xml/dom/minidom.py", line 287, in _append_child
last.__dict__["nextSibling"] = node
MemoryError
The xml-feed I'm parsing is huge, so that might be the problem. But what to do about it?

Categories