Why is markdown finding weird characters in my exported wordpress xml file? - django

Mac OSX 10.7
Python 2.7
Django 1.3
Markdown 2.0.3
I am trying to migrate from a wordpress blog to a django-powered one. I am using pigmonkey's django-basic-apps for it's xml parsing script, but every time I attempt it, markdown keeps raising "markdown.MarkdownException: UnicodeDecodeError: Markdown only accepts unicode or ascii input."
Full traceback:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_basic_apps-0.8-py2.7.egg/basic/blog/management/commands/wordpress_import.py", line 100, in handle
post.save()
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_basic_apps-0.8-py2.7.egg/basic/blog/models.py", line 77, in save
self.body_rendered = mark_safe(formatter(self.body_rendered, filter_name=self.markup))
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_markup-0.3-py2.7.egg/django_markup/markup.py", line 90, in __call__
return filter_class().render(text, **filter_kwargs)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/django_markup-0.3-py2.7.egg/django_markup/filter/markdown_filter.py", line 21, in render
text = markdown(text, **kwargs)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/markdown/__init__.py", line 598, in markdown
return md.convert(text)
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/markdown/__init__.py", line 377, in convert
message(CRITICAL, 'UnicodeDecodeError: Markdown only accepts unicode or ascii input.')
File "/Users/mycomputer/.virtualenvs/zachswhite/lib/python2.7/site-packages/markdown/__init__.py", line 112, in message
raise MarkdownException, text
markdown.MarkdownException: UnicodeDecodeError: Markdown only accepts unicode or ascii input.
There's nothing outside unicode in there, that I've found maybe you guys would have better luck.
I can upload the xml file too, if that would help

This should be fixed as of my most recent commit to my fork of django-basic-apps. The error was caused by passing the post's body and tease through the inline parser before passing it to Markdown (which is necessary for other reasons). I don't fully understand why the error was being thrown, but you can read today's commit message for what I do know:
https://github.com/pigmonkey/django-vellum/commit/1d5fb4743a7fc34e4b6cd415144ad232bbc3f0ad
By the way, I just noticed this question today as I was doing some Googling, trying to understand this error. For future reference, if you contact me through Github, or through my website, or create an Issue for the project on Github, or email me, I'll probably respond a lot faster! I'm always interested to hear about any bugs found in my projects.

Related

Google Cloud Speech to Text API stopped working

I signed up for Google Cloud Speech to Text API for a project I am undertaking. This morning, I was able to convert speech to text successfully. In the evening, I resumed the work and all of a sudden, it stops working. It doesn't take any input and upon keyword interrupt I get the following message. I am not sure why it has suddenly decided not to work. I restarted my laptop thinking it would be some microphone issue. Then, I downloaded the code and re-ran, yet no positive outcome. Below is the message I get.
Traceback (most recent call last):
File "/Users/ajayshah/Downloads/s2t.py", line 174, in <module>
main()
File "/Users/ajayshah/Downloads/s2t.py", line 167, in main
responses = client.streaming_recognize(streaming_config, requests)
File "/Users/ajayshah/opt/miniconda3/lib/python3.9/site-packages/google/cloud/speech_v1/helpers.py", line 81, in streaming_recognize
return super(SpeechHelpers, self).streaming_recognize(
File "/Users/ajayshah/opt/miniconda3/lib/python3.9/site-packages/google/cloud/speech_v1/services/speech/client.py", line 605, in streaming_recognize
response = rpc(requests, retry=retry, timeout=timeout, metadata=metadata,)
File "/Users/ajayshah/opt/miniconda3/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py", line 142, in __call__
return wrapped_func(*args, **kwargs)
File "/Users/ajayshah/opt/miniconda3/lib/python3.9/site-packages/google/api_core/retry.py", line 283, in retry_wrapped_func
return retry_target(
File "/Users/ajayshah/opt/miniconda3/lib/python3.9/site-packages/google/api_core/retry.py", line 218, in retry_target
time.sleep(sleep)
KeyboardInterrupt

Why am I getting errors when trying to invoke Django Python shell?

My current version of python is 2.7.10 and version of Django is 1.9.1, path.py is 8.1.2 but every time when I'm trying to invoke python shell by command:
$ python manage.py shell I'm getting a lot of errors and the ending of them looks like:
Error in sys.excepthook:
Traceback (most recent call last):
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\CrashHandler.py", line 157, in __call__
report.write(self.make_report(traceback))
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\CrashHandler.py", line 215, in make_report
rpt_add('BZR revision : %s \n\n' % Release.revision)
AttributeError: 'module' object has no attribute 'revision'
Original exception was:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 69, in handle
self.run_shell(shell=options['interface'])
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 58, in run_shell
return getattr(self, shell)()
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 41, in ipython
ip()
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 22, in _ipython_pre_011
shell = IPShell(argv=[])
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\Shell.py", line 73, in __init__
debug=debug,shell_class=shell_class)
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\ipmaker.py", line 521, in make_IPython
IP.pre_config_initialization()
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\iplib.py", line 835, in pre_config_initialization
self.db = pickleshare.PickleShareDB(rc.ipythondir + "/db")
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\Extensions\pickleshare.py", line 53, in __init__
if not self.root.isdir():
TypeError: _isdir() takes exactly 1 argument (0 given)
How can I overcome the problem?
From doing a quick search, it looks like this error happens when both Django and IPython are installed, since apparently Django will attempt to use the IPython shell.
The first resource with someone who had a similar issue:
run python manage.py shell occurs errors
And in the link above, one of the comments on the OP's question suggested looking at this separate thread for answers:
https://superuser.com/questions/318655/error-running-ipython3-on-xp-typeerror-isdir-takes-exactly-1-argument-0-gi
The winning answer says the following:
Finally decided to give this another stab, and managed to get it to
work. The solution is a two-line change in the
ipython-0.11-py3.2.egg\IPython\utils\pickleshare.py file, line 52:
Before:
if not self.root.isdir():
self.root.makedirs()
After:
if not os.path.isdir(self.root):
os.makedirs(self.root)

DjangoUnicodeDecodeError while makemigrations after upgrading to 1.8

Recently I've upgraded my Django from 1.6.5 to 1.8.3. I have been using South, so, following tutorial, I've removed South, deleted old migrations and run makemigrations. Then I got error:
[mefioo#ibmed-server kariera_naukowa]$ env/bin/python src/manage.py makemigrations
Migrations for 'editcv':
0001_initial.py:
- Create model Adresy
- Create model Affiliacja
[...all models from models.py...]
- Create model ZalRo
- Add field WszysCz to wlasne
[...so far only ForeignKeys, but not all of them...]
- Add field user to adresy
Traceback (most recent call last):
File "src/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 143, in handle
self.write_migration_files(changes)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 171, in write_migration_files
migration_string = writer.as_string()
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 166, in as_string
operation_string, operation_imports = OperationWriter(operation).serialize()
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 124, in serialize
_write(arg_name, arg_value)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 75, in _write
arg_string, arg_imports = MigrationWriter.serialize(item)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 303, in serialize
item_string, item_imports = cls.serialize(item)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 377, in serialize
return cls.serialize_deconstructed(path, args, kwargs)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 268, in serialize_deconstructed
arg_string, arg_imports = cls.serialize(arg)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/db/migrations/writer.py", line 296, in serialize
value = force_text(value)
File "/home/mefioo/public_html/kariera_naukowa/env/lib/python2.7/site-packages/django/utils/encoding.py", line 102, in force_text
raise DjangoUnicodeDecodeError(s, *e.args)
django.utils.encoding.DjangoUnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128). You passed in <django.utils.functional.__proxy__ object at 0x268a9d0> (<class 'django.utils.functional.__proxy__'>)
I check out, 0xc3 is à or Ä which I certainly do not use (it does not even exist in polish alphabet).
One of the fk that passed is
wydzial = models.ForeignKey(Wydzial, verbose_name="Wydział")
and it contains polish 'ł', but everything is alright.
What am I missing here?
You should avoid problems if you use unicode strings in your models, e.g. verbose_name=u"Wydział".
You might prefer to import unicode_literals from the future library, as recommended by the Django docs. Be careful if adding this to an existing module though!
from __future__ import unicode_literals
Unicode vs python string problem. The Django docs have moved further down the path toward python 3, so they aren't in the habit of warning you anymore. In python2, put a u in front of the string, e.g., u"Wydział". Since you're running 2.7, you can try from __future__ import unicode_literals. Note that this second solution could break some other things in your project.

"'django_mongodb_engine' isn't an available database backend" when pushing to Heroku

I have a Django app that successfully ran on Heroku and uses mongodb engine. All of a sudden, I can not push it anymore. It does not seem to recognize the django_mongodb_engine module anymore. I even reverted all changes to the version that last ran, but it's still the same. I suspect a version conflict or so, but can not figure out how to fix it.
This is the error I'm getting:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 46, in handle_noargs
from django.db.models.loading import get_models
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 51, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named utils
And these are the important parts from the requirements.txt:
hg+https://bitbucket.org/wkornewald/django-nonrel
git+https://github.com/django-nonrel/mongodb-engine
hg+https://bitbucket.org/wkornewald/djangotoolbox
pymongo==2.2.1
pytz==2012d
I'm especially confused because I reverted all changes. Exactly this code with the same configuration ran perfectly (and still does on my production server), just pushing does not work.
Thanks
Simon
Of course, just when I asked on SO I figure out the answer :-)
I don't know why exactly, but defining the exact revision that i want to check out solved the problem.
So the requirements.txt looks now like this:
-e hg+http://bitbucket.org/wkornewald/django-nonrel#be48c152abc6b15e45155e2bbcfd69c665ccb536#egg=Django-dev
-e git+https://github.com/django-nonrel/mongodb-engine#52257b5d90dcfaa564e708264a9cfe591d301fe6#egg=django_mongodb_engine-dev
-e hg+https://bitbucket.org/wkornewald/djangotoolbox#a8cdf61ba9c0cdc7cbbbd37d693e9a222d9a8e5f#egg=djangotoolbox-dev
pymongo==2.2.1
pytz==2012d

How to install neo4django in virtual environment

I receive the error below when trying to install neo4django in my virtual environment. Not sure what the problem is. The server is running on my machine and py2neo works with the restful api, but not neo4django.
I'm running ubuntu 12.0.4 with the latest version of neo4j installed (1.9-M01) and jdk 1.7 (openjkd) installed with JAVA_HOME pointing to: /usr/lib/jvm/java-7-openjdk-amd64
Traceback (most recent call last): File "manage.py", line 10, in
execute_from_command_line(sys.argv) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/django/core/management/init.py",
line 443, in execute_from_command_line
utility.execute() File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/django/core/management/init.py",
line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/django/core/management/base.py",
line 196, in run_from_argv
self.execute(*args, **options.dict) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/django/core/management/base.py",
line 232, in execute
output = self.handle(*args, **options) File "/home/alan/workspace/neowiki/neowiki/nodes/management/commands/testcmd.py",
line 10, in handle
pete = Person.objects.create(name='Pete') File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4django/db/models/manager.py",
line 41, in create
return self.get_query_set().create(*kwargs) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4django/db/models/query.py",
line 747, in create
return super(NodeQuerySet, self).create(*kwargs) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/django/db/models/query.py",
line 377, in create
obj.save(force_insert=True, using=self.db) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4django/db/models/base.py",
line 325, in save
return super(NodeModel, self).save(using=using, **kwargs) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/django/db/models/base.py",
line 463, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update) File
"/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4django/db/models/base.py",
line 340, in save_base
self._save_neo4j_node(using) File "", line 2, in _save_neo4j_node File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4django/db/models/base.py",
line 115, in trans_method
ret = func(*args, **kw) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4django/db/models/base.py",
line 370, in _save_neo4j_node
typesToIndex=type_names_to_index) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4django/neo4jclient.py",
line 179, in gremlin_tx
return self.gremlin(script, tx=True, **params) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4django/neo4jclient.py",
line 168, in gremlin
params) File "/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4django/neo4jclient.py",
line 153, in send_script
script_rv = ext.execute_script(s, params=params, **execute_kwargs) File
"/home/alan/workspace/neowiki/venv/local/lib/python2.7/site-packages/neo4jrestclient/client.py",
line 1960, in call
raise StatusException(response.status, msg) neo4jrestclient.request.StatusException: Error [400]: Bad Request. Bad
request syntax or unsupported method. Invalid data sent:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed: Script4.groovy: 94: unable to resolve class
org.neo4j.cypher.javacompat.CypherParser # line 94, column 1.
import org.neo4j.cypher.javacompat.CypherParser ^
1 error
My requirements.txt includes:
-e git://github.com/scholrly/neo4django.git#eefdf6a122fdbe26c62b6563f9ff6b30a4de2f93#egg=neo4django-dev
neo4jrestclient==1.7.0
Any help is greatly appreciated!
From what I can see, your installation is fine. The problem is the version of Neo4j.
So far, we only support Neo4j 1.6-1.8. While I try to support all major releases in use, I typically extend support for milestones closer to a general release. For example, I didn't extend support to Neo4j 1.8 until it hit milestone 6.
Is there a particular reason you're using 1.9M01, or would the most recent stable release (1.8GA) suffice?