Search code examples
pythonpython-sphinxread-the-docs

Ascii decoding error when using Sphinx on Read The Docs - locally it works


I started with writing my documentation for my python/django project.

This happens:

Running Sphinx v1.2
loading translations [en]... done
building [readthedocs]: targets for 18 source files that are out of date
updating environment: 18 added, 0 changed, 0 removed
reading sources... [  5%] administrator-guide/customizing
reading sources... [ 11%] administrator-guide/index
reading sources... [ 16%] developer-guide/index
reading sources... [ 22%] index
reading sources... [ 27%] modules/booking
Sphinx Standard Error
Sphinx error:
'ascii' codec can't decode byte 0xef in position 475: ordinal not in range(128)

I understand, this is an encoding problem.

But, all my files are encoded with UTF-8 and it works locally (Windows).

This is my modules/booking.rst. And in this directory are my booking-module-files.


Solution

  • As described by PEP 0263, adding this to the top of your source file ensures it works properly with utf-8 encoding.

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    

    Personally hit this snag when I had some Japanese characters in a string literal in a source file.